TSQL – Equivalent of On Update CURRENT_TIMESTAMP(MYSQL)
Requires a trigger in MS-SQL to achieve the same behaviour. Update a timestamp only when a field changes (colTest).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
CREATE TRIGGER <triggerName> ON <table> FOR UPDATE AS BEGIN SET NOCOUNT ON; IF UPDATE (colTest) BEGIN UPDATE <table> SET <field> = GETDATE(),colPersistent =I.colTest FROM <table> S INNER JOIN Inserted I ON S.id = I.id WHERE I.colTest<> S.colPersistent end END GO |
A persistent field is required as S.colTest is NULL as this trigger is executed.