AdventureWorks2019
DatabaseLog
//
Audit table tracking all DDL changes made to the AdventureWorks database. Data is captured by the database trigger ddlDatabaseTriggerLog.
Created: Modified:
Columns
-
//${escapify(column.description)}[int] IDENTITY (1,1) NOT NULL
-
//${escapify(column.description)}[datetime] NOT NULL
-
//${escapify(column.description)}[sysname] NOT NULL
-
//${escapify(column.description)}[sysname] NOT NULL
-
//${escapify(column.description)}[sysname] NULL
-
//${escapify(column.description)}[sysname] NULL
-
//${escapify(column.description)}[nvarchar](MAX) NOT NULL
-
//${escapify(column.description)}[xml] NOT NULL
Indexes
-
//Nonclustered index created by a primary key constraint.PK_DatabaseLog_DatabaseLogIDUNIQUE NONCLUSTEREDDatabaseLogID
Sample Data
DatabaseLogID
PostTime
DatabaseUser
Event
Schema
Object
TSQL
XmlEvent
1
dbo
CREATE_TABLE
dbo
ErrorLog
CREATE TABLE [dbo].[ErrorLog](
[ErrorLogID] [int] IDENTITY (1, 1) NOT NULL,
[ErrorTime] [datetime] NOT NULL CONSTRAINT [DF_ErrorLog_ErrorTime] DEFAULT (GETDATE()),
[UserName] [sysname] NOT NULL,
[ErrorNumber] [int] NOT NULL,
[ErrorSeverity] [int] NULL,
[ErrorState] [int] NULL,
[ErrorProcedure] [nvarchar](126) NULL,
[ErrorLine] [int] NULL,
[ErrorMessage] [nvarchar](4000) NOT NULL
) ON [PRIMARY]
[xml]
2
dbo
ALTER_TABLE
dbo
ErrorLog
ALTER TABLE [dbo].[ErrorLog] WITH CHECK ADD
CONSTRAINT [PK_ErrorLog_ErrorLogID] PRIMARY KEY CLUSTERED
(
[ErrorLogID]
) ON [PRIMARY]
[xml]
5
dbo
CREATE_TYPE
dbo
AccountNumber
CREATE TYPE [AccountNumber] FROM nvarchar(15) NULL;
[xml]
6
dbo
CREATE_TYPE
dbo
Flag
CREATE TYPE [Flag] FROM bit NOT NULL;
[xml]
21
dbo
CREATE_XML_SCHEMA_COLLECTION
HumanResources
HRResumeSchemaCollection
CREATE XML SCHEMA COLLECTION [HumanResources].[HRResumeSchemaCollection] AS
'
Home|Work|Permanent
High School|Associate|Bachelor|Master|Doctorate
In case the institution does not follow a GPA system
ISO 3166 Country Code
Voice|Fax|Pager
';
[xml]
23
dbo
ALTER_XML_SCHEMA_COLLECTION
Production
ProductDescriptionSchemaCollection
ALTER XML SCHEMA COLLECTION [Production].[ProductDescriptionSchemaCollection] ADD
'
Product description has a summary blurb, if its manufactured elsewhere it
includes a link to the manufacturers site for this component.
Then it has optional zero or more sequences of features, pictures, categories
and technical specifications.
Pictures of the component, some standard sizes are "Large" for zoom in, "Small" for a normal web page and "Thumbnail" for product listing pages.
Features of the component that are more "sales" oriented.
A single technical aspect of the component.
A single categorization element that designates a classification taxonomy and a code within that classification type. Optional description for default display if needed.
';
[xml]
3
dbo
CREATE_PROCEDURE
dbo
uspPrintError
-- uspPrintError prints error information about the error that caused
-- execution to jump to the CATCH block of a TRY...CATCH construct.
-- Should be executed from within the scope of a CATCH block otherwise
-- it will return without printing any error information.
CREATE PROCEDURE [dbo].[uspPrintError]
AS
BEGIN
SET NOCOUNT ON;
-- Print error information.
PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) +
', Severity ' + CONVERT(varchar(5), ERROR_SEVERITY()) +
', State ' + CONVERT(varchar(5), ERROR_STATE()) +
', Procedure ' + ISNULL(ERROR_PROCEDURE(), '-') +
', Line ' + CONVERT(varchar(5), ERROR_LINE());
PRINT ERROR_MESSAGE();
END;
[xml]
7
dbo
CREATE_TYPE
dbo
NameStyle
CREATE TYPE [NameStyle] FROM bit NOT NULL;
[xml]
8
dbo
CREATE_TYPE
dbo
Name
CREATE TYPE [Name] FROM nvarchar(50) NULL;
[xml]
9
dbo
CREATE_TYPE
dbo
OrderNumber
CREATE TYPE [OrderNumber] FROM nvarchar(25) NULL;
[xml]
4
dbo
CREATE_PROCEDURE
dbo
uspLogError
-- uspLogError logs error information in the ErrorLog table about the
-- error that caused execution to jump to the CATCH block of a
-- TRY...CATCH construct. This should be executed from within the scope
-- of a CATCH block otherwise it will return without inserting error
-- information.
CREATE PROCEDURE [dbo].[uspLogError]
@ErrorLogID [int] = 0 OUTPUT -- contains the ErrorLogID of the row inserted
AS -- by uspLogError in the ErrorLog table
BEGIN
SET NOCOUNT ON;
-- Output parameter value of 0 indicates that error
-- information was not logged
SET @ErrorLogID = 0;
BEGIN TRY
-- Return if there is no error information to log
IF ERROR_NUMBER() IS NULL
RETURN;
-- Return if inside an uncommittable transaction.
-- Data insertion/modification is not allowed when
-- a transaction is in an uncommittable state.
IF XACT_STATE() = -1
BEGIN
PRINT 'Cannot log error since the current transaction is in an uncommittable state. '
+ 'Rollback the transaction before executing uspLogError in order to successfully log error information.';
RETURN;
END
INSERT [dbo].[ErrorLog]
(
[UserName],
[ErrorNumber],
[ErrorSeverity],
[ErrorState],
[ErrorProcedure],
[ErrorLine],
[ErrorMessage]
)
VALUES
(
CONVERT(sysname, CURRENT_USER),
ERROR_NUMBER(),
ERROR_SEVERITY(),
ERROR_STATE(),
ERROR_PROCEDURE(),
ERROR_LINE(),
ERROR_MESSAGE()
);
-- Pass back the ErrorLogID of the row inserted
SET @ErrorLogID = @@IDENTITY;
END TRY
BEGIN CATCH
PRINT 'An error occurred in stored procedure uspLogError: ';
EXECUTE [dbo].[uspPrintError];
RETURN -1;
END CATCH
END;
[xml]
10
dbo
CREATE_TYPE
dbo
Phone
CREATE TYPE [Phone] FROM nvarchar(25) NULL;
[xml]
12
dbo
CREATE_SCHEMA
HumanResources
HumanResources
CREATE SCHEMA [HumanResources] AUTHORIZATION [dbo];
[xml]
11
dbo
CREATE_FUNCTION
dbo
ufnLeadingZeros
CREATE FUNCTION [dbo].[ufnLeadingZeros](
@Value int
)
RETURNS varchar(8)
WITH SCHEMABINDING
AS
BEGIN
DECLARE @ReturnValue varchar(8);
SET @ReturnValue = CONVERT(varchar(8), @Value);
SET @ReturnValue = REPLICATE('0', 8 - DATALENGTH(@ReturnValue)) + @ReturnValue;
RETURN (@ReturnValue);
END;
[xml]
13
dbo
CREATE_SCHEMA
Person
Person
CREATE SCHEMA [Person] AUTHORIZATION [dbo];
[xml]
14
dbo
CREATE_SCHEMA
Production
Production
CREATE SCHEMA [Production] AUTHORIZATION [dbo];
[xml]
15
dbo
CREATE_SCHEMA
Purchasing
Purchasing
CREATE SCHEMA [Purchasing] AUTHORIZATION [dbo];
[xml]
16
dbo
CREATE_SCHEMA
Sales
Sales
CREATE SCHEMA [Sales] AUTHORIZATION [dbo];
[xml]
17
dbo
CREATE_XML_SCHEMA_COLLECTION
Person
AdditionalContactInfoSchemaCollection
CREATE XML SCHEMA COLLECTION [Person].[AdditionalContactInfoSchemaCollection] AS
'
';
[xml]
168
dbo
CREATE_INDEX
Person
AK_AddressType_rowguid
CREATE UNIQUE INDEX [AK_AddressType_rowguid] ON [Person].[AddressType]([rowguid]) ON [PRIMARY]
[xml]
18
dbo
ALTER_XML_SCHEMA_COLLECTION
Person
AdditionalContactInfoSchemaCollection
ALTER XML SCHEMA COLLECTION [Person].[AdditionalContactInfoSchemaCollection] ADD
'
';
[xml]
183
dbo
CREATE_INDEX
Production
AK_Culture_Name
CREATE UNIQUE INDEX [AK_Culture_Name] ON [Production].[Culture]([Name]) ON [PRIMARY]
[xml]
188
dbo
CREATE_INDEX
Sales
IX_Customer_TerritoryID
CREATE INDEX [IX_Customer_TerritoryID] ON [Sales].[Customer]([TerritoryID]) ON [PRIMARY]
[xml]
19
dbo
ALTER_XML_SCHEMA_COLLECTION
Person
AdditionalContactInfoSchemaCollection
ALTER XML SCHEMA COLLECTION [Person].[AdditionalContactInfoSchemaCollection] ADD
'
';
[xml]
193
dbo
CREATE_INDEX
Person
IX_EmailAddress_EmailAddress
CREATE INDEX [IX_EmailAddress_EmailAddress] ON [Person].[EmailAddress]([EmailAddress]) ON [PRIMARY]
[xml]