Friday, 24 October 2008

SQL: Script traceability

A small snippet for automaticly in SQL Server get date and user name into columns like CREATED_DATE, CREATED_BY, LATEST_UPDATED_BY etc:



BEGIN TRAN
UPDATE [table]
SET
LATEST_CHANGED_DATE = getDate(),
LATEST_CHANGED_BY = SYSTEM_USER
WHERE [critera] = 'True'
COMMIT






 

In table:


LATEST_CHANGED_DATE       LATEST_CHANGED_BY
2008-10-24 10:37:26.470   Stefan

No comments: