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.
Author |
Topic |
Patyk
Yak Posting Veteran
74 Posts |
Posted - 2014-09-08 : 13:08:42
|
I need to use SQL trigger function to check for update in my sales order table and if the column updated the record should be copied to an audit table.For example my sales order table is as followsorder numberorder dateorder statusThe trigger should check if order status changes to 9 if yes copy the record line to the audit table.Any help appreciated.thanks |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-09-08 : 15:13:39
|
You can use the UPDATE() function in the trigger to determine if the column was updated. Here's an example:CREATE TRIGGER trig1ON YourTableAFTER UPDATE ASIF (UPDATE(OrderStatus))BEGIN INSERT INTO AuditTable (...) SELECT ... FROM inserted WHERE OrderStatus = 9ENDGOTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
Patyk
Yak Posting Veteran
74 Posts |
Posted - 2014-09-08 : 17:25:34
|
What would be the best way to schedule the above trigger?Thanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-09-08 : 19:14:33
|
You don't schedule a trigger. The trigger fires for the specified DML action. Each time an update happens to the table, it runs.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
|
|
|