September 24, 2015 at 8:21 am
It has been a while since I have written a Trigger.
I need an INSERT UPDATE Trigger that will update the DateModified Column to GetDate().
I recall it being very simple but the examples that I'm finding are not that straight forward.:blush:
Does anyone have an example?
I need to find an example of an INSERT UPDATE Trigger as well.
Thanks.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
September 24, 2015 at 8:39 am
Welsh Corgi (9/24/2015)
It has been a while since I have written a Trigger.I need an INSERT UPDATE Trigger that will update the DateModified Column to GetDate().
I recall it being very simple but the examples that I'm finding are not that straight forward.:blush:
Does anyone have an example?
I need to find an example of an INSERT UPDATE Trigger as well.
Thanks.
Something like this.
update t
set DateModified = GETDATE()
from YourTable t
join inserted i on t.PrimaryKey = i.PrimaryKey
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 24, 2015 at 10:33 am
You just need an update trigger. If DateModified is set DEFAULT GETDATE() that'll handle the assignment for the insert, and then Sean's code is all that's needed for the update trigger
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply