How to track when a row was created / updated automatically in SQL Server?

Is there a way to automatically tell SQL Server that all tables must have a timestamp to insert and update?

What, probably, is a lot of repetitive work for this?

Or is there another / more efficient way to do this with a transaction log?

+6
source share
3 answers

Take a look at AutoAudit

This will add columns to the table and create DML triggers to manage these columns, as well as save the audit log table

I found it very useful

, DDL, .

+4

RowCreated DATETIME DEFAULT (GETDATE()) , , - , RowModified DATETIME.

AFTER UPDATE RowModified :

CREATE TRIGGER dbo.trg_YourTableUpdated
ON dbo.YourTable AFTER UPDATE
AS BEGIN
    UPDATE dbo.YourTable
    SET RowModified = GETDATE()
    FROM INSERTED i
    WHERE dbo.YourTable.ID = i.ID
END
+5

DML- SQL Server, defaults, - default

+2

All Articles