Created
January 5, 2020 15:37
-
-
Save LiCongMingDeShujuku/bb949d9bf3252bd2a20a356b7185f3a7 to your computer and use it in GitHub Desktop.
Create Simple Modified Date Column In Your Table To Record Changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use [compliance]; | |
set nocount on | |
create table [STANDARD_RULES_00] | |
( | |
[lineid] int identity(1,1) | |
, [createdate] datetime null | |
, [statements] varchar(max) | |
, [modifieddate] datetime null | |
, [description] varchar(max) | |
) | |
go | |
create trigger trig_post_insert | |
on [dbo].[STANDARD_RULES_00] | |
after insert | |
as | |
begin | |
update [dbo].[STANDARD_RULES_00] | |
set [createdate] = getdate() | |
from dbo.[STANDARD_RULES_00] sr | |
where exists (select 1 from inserted i where i.[lineid] = sr.[lineid]); | |
end | |
go | |
create trigger trig_post_update | |
on [dbo].[STANDARD_RULES_00] | |
after update | |
as | |
begin | |
update [dbo].[standard_rules_00] | |
set [modifieddate] = getdate() | |
from dbo.[STANDARD_RULES_00] sr | |
where exists (select 1 from inserted i where i.[lineid] = sr.[lineid]); | |
end | |
go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment