Trigger
I want to write a trigger that updates one table after a value is inserted,updated or deleted into another table..
for instance i have this table userinfo which contains the employee details once a new value is entered into this table i want a trigger to update another table viz syncinfo, can anyone tell me the logic through which i can do this procedure?
Regards,
Venki
[388 byte] By [
Macho] at [2008-1-10]
Hi,
You can create trigger on the table where in following way:
CREATE TRIGGER syncinfo ON [userinfo]
FOR INSERT
AS
UPDATE p SET p.columnname='Test'
FROM anothertable p
Also you can do this by the stored procedure as triggres should be used in foll senarios:
1) if the database is de-normalized and requires an automated way to update redundant data contained in multiple tables 2) if customized messages and complex error handling are required, or if a value in one table must be validated against a non-identical value in another table.
Regards
Jayant
Hi Venki,
You can do the same functionality through procedures.
I believe that you have procedures for insert/update/delete data into the userinfo table. On the same procedure, you can implement the update information in syncinfo table.
Thanks
Naras.
Hi,
You can also use:
Code Block
select * from inserted
in order to gather the new data, and
Code Block
select * from deleted
to gather the old values. You could, for instance, put them into variables and the update the other tables.
regards.