Last active
March 6, 2021 16:45
-
-
Save mrjamiebowman/a6c29c2234b208789eaaf05931281abc to your computer and use it in GitHub Desktop.
SQL Error Logs
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 SCHEMA logs AUTHORIZATION dbo | |
CREATE TABLE [logs].[Errors]( | |
[ErrorId] [int] IDENTITY(1,1) NOT NULL, | |
[UserName] [varchar](100) NULL, | |
[ErrorNumber] [int] NULL, | |
[ErrorState] [int] NULL, | |
[ErrorSeverity] [int] NULL, | |
[ErrorLine] [int] NULL, | |
[ErrorProcedure] [varchar](max) NULL, | |
[ErrorMessage] [varchar](max) NULL, | |
[ErrorDateTime] [datetime2](7) NULL | |
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] | |
GO |
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
BEGIN TRY | |
BEGIN TRANSACTION | |
COMMIT | |
END TRY | |
BEGIN CATCH | |
ROLLBACK | |
INSERT INTO logs.Errors VALUES | |
(SUSER_SNAME(), | |
ERROR_NUMBER(), | |
ERROR_STATE(), | |
ERROR_SEVERITY(), | |
ERROR_LINE(), | |
ERROR_PROCEDURE(), | |
ERROR_MESSAGE(), | |
GETUTCDATE()); | |
THROW | |
END CATCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment