0
Posted on 1:49 AM by Softminer and filed under

1. to add Created and Modified column to Table
2. add Update trigger
3. add Insert trigger

ALTER TABLE Table1
ADD Created datetime null,Modified datetime null
go

CREATE TRIGGER [TriggerUpdate]
ON [dbo].[Table1]
FOR UPDATE
AS
update Table1 set Modified = getdate() where Id in (SELECT Id FROM inserted)
go

CREATE TRIGGER [TriggerInsert]
ON [dbo].[Table1]
FOR INSERT
AS
update Table1 set Created= getdate() where Id in (SELECT Id FROM inserted)
0
Responses to ... How to add Created and Modified to SQL server tables using Trigger