Can we pass parameters into trigerrs?
-
I have written an update trigger. It is given below: CREATE TRIGGER Trg_OnUpdateJSComman ON [dbo].[JSComman] FOR UPDATE AS begin declare @uid bigint update JSCvs set LastUpdated=getdate() where (UID=@uid) end if any updates happen in the JSComman table this trigger will have to execute. but i need to pass the uid into the trigger for this to execute. is it possible to pass parameters into the trigger? Thanks in advance. Lavanya:)
-
I have written an update trigger. It is given below: CREATE TRIGGER Trg_OnUpdateJSComman ON [dbo].[JSComman] FOR UPDATE AS begin declare @uid bigint update JSCvs set LastUpdated=getdate() where (UID=@uid) end if any updates happen in the JSComman table this trigger will have to execute. but i need to pass the uid into the trigger for this to execute. is it possible to pass parameters into the trigger? Thanks in advance. Lavanya:)
You shouldn't need to pass a parameter into a trigger. As a simplification, it has access to the INSERTED and DELETED tables, so you could write the above trigger as:
UPDATE JSCvs SET LastUpdated = GETDATE() WHERE UID = (SELECT UID FROM INSERTED)
Whenever you do an update, the tables INSERTED and DELETED store copies of the modification. Deleted stores the old version, and Inserted stores the updated version. I hope that helps.Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world." Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that." Deja View - the feeling that you've seen this post before.
-
You shouldn't need to pass a parameter into a trigger. As a simplification, it has access to the INSERTED and DELETED tables, so you could write the above trigger as:
UPDATE JSCvs SET LastUpdated = GETDATE() WHERE UID = (SELECT UID FROM INSERTED)
Whenever you do an update, the tables INSERTED and DELETED store copies of the modification. Deleted stores the old version, and Inserted stores the updated version. I hope that helps.Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world." Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that." Deja View - the feeling that you've seen this post before.
Thank you. I solved the problem. :rose: