Skip to content

Instantly share code, notes, and snippets.

@mrjamiebowman
Last active March 6, 2021 16:45
Show Gist options
  • Save mrjamiebowman/a6c29c2234b208789eaaf05931281abc to your computer and use it in GitHub Desktop.
Save mrjamiebowman/a6c29c2234b208789eaaf05931281abc to your computer and use it in GitHub Desktop.
SQL Error Logs
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
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