View Single Post
  #4 (permalink)  
Old 02-08-10, 23:35
TerryP TerryP is offline
Registered User
 
Join Date: Feb 2007
Posts: 38
Hi

Apart from the issue you have for multiple returned FULL, your trigger will also be in trouble if multiple rows inserted at the same time like below:

INSERT INTO [dbo].[Disciplinary_Action_Form]
SELECT top 100 *
FROM [dbo].[Other_Disciplinary_Action_Form]

Your trigger will only take care of the last row entered out of 100 rows.

You need to loop through all the rows in the INSERTED table as below:

DECLARE Disciplinary_Action_Form_Cursor CURSOR FOR
SELECT Name
FROM Inserted

OPEN Disciplinary_Action_Form_Cursor
FETCH NEXT FROM Disciplinary_Action_Form_Cursor INTO @Name

-- Loop through cursor until finished
WHILE @@FETCH_STATUS = 0
BEGIN

-- place your code here for after insert action


--Fetch_Next:
FETCH NEXT FROM Disciplinary_Action_Form_Cursor INTO @Name

END

This routine also should be applied to UPDATE and DELETE triggers as well.
Reply With Quote