Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Issue with Update trigger

Author  Topic 

sql_2k
Starting Member

26 Posts

Posted - 2008-05-26 : 06:22:50
Hi All

Please help me resolving below issue.

I have a table tbl_test1 with 2 columns (ID & Value) On update value of this table the ID field should be inserted to a tbl_Test2 table. I hv designed a simple trigger to track. But while checking the tbl_test2 value am getting multiple insert on a single update on tbl_test1.



ALTER TRIGGER [trgUpdtest] ON [dbo].[tbl_Test1]
FOR UPDATE
AS
IF EXISTS(SELECT * FROM INSERTED)
BEGIN
INSSERT INTO tbl_test2
Select top 1 ID FROM INSERTED
END

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-26 : 06:32:50
How will you be performing the update? Are you doing it in bulk?
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-05-26 : 16:37:34
quote:
Originally posted by sql_2k


INSSERT INTO tbl_test2
Select top 1 ID FROM INSERTED




Triggers fire once for a statement, not once per row. If the update affects more than 1 row, there will be multiple rows in the inserted table.

--
Gail Shaw
Go to Top of Page
   

- Advertisement -