Trigger on update as insert data in table ..... [modified]
-
Hi Frends I am trying to write a trigger ....whenever a particular column updates in my table then this record i.e. updated should be inserted in another table. but problem is that its inserting all the records in IInd table whenever i update the record in first table. My trigger is...... CREATE TRIGGER CreateTrans ON [dbo].[Table1] FOR UPDATE AS IF (COLUMNS_UPDATED() & 49)=49 BEGIN INSERT INTO [Table2](x.ID) SELECT ID FROM Table1 x END GO Thanks Dinesh Sharma -- modified at 5:25 Wednesday 26th July, 2006
-
Hi Frends I am trying to write a trigger ....whenever a particular column updates in my table then this record i.e. updated should be inserted in another table. but problem is that its inserting all the records in IInd table whenever i update the record in first table. My trigger is...... CREATE TRIGGER CreateTrans ON [dbo].[Table1] FOR UPDATE AS IF (COLUMNS_UPDATED() & 49)=49 BEGIN INSERT INTO [Table2](x.ID) SELECT ID FROM Table1 x END GO Thanks Dinesh Sharma -- modified at 5:25 Wednesday 26th July, 2006
You don't have any join to the "updated" record. Try something like:- CREATE TRIGGER CreateTrans ON [dbo].[Table1] FOR UPDATE AS IF (COLUMNS_UPDATED() & 49)=49 BEGIN INSERT INTO [Table2](x.ID) SELECT x.ID FROM Table1 x INNER JOIN INSERTED ON x.Id = INSERTED.Id END GO
'--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd