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)
Permalink 0 comments
0
Responses to ... How to add Created and Modified to SQL server tables using Trigger