Created
August 17, 2017 17:27
-
-
Save randyburden/69b7d790990621493a58584343314643 to your computer and use it in GitHub Desktop.
Standard set of SQL Server audit columns with default constraints
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
CREATE TABLE TableName | |
( | |
TableNameId INT NOT NULL IDENTITY(1,1), | |
/* Other columns */ | |
CreatedDate DATETIME2 NOT NULL CONSTRAINT [DF_TableName_CreatedDate] DEFAULT (GETDATE()), | |
CreatedBy VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_CreatedBy] DEFAULT (SUSER_SNAME()), | |
CreatedByHostName VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_CreatedByHostName] DEFAULT (HOST_NAME()), | |
ModifiedDate DATETIME2 NOT NULL CONSTRAINT [DF_TableName_ModifiedDate] DEFAULT (GETDATE()), | |
ModifiedBy VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_ModifiedBy] DEFAULT (SUSER_SNAME()), | |
ModifiedByHostName VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_ModifiedByHostName] DEFAULT (HOST_NAME()) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment