Log errors in SQL Server that would otherwise go unnoticed (+ examples)

Preparation

Counting the number of records in the sys.columns table
Trying to count the number of records in a non-existent schema

Detecting and logging errors

Logging your errors

EXEC dbo.tablecounter 'sys', 'columns';
EXEC dbo.tablecounter 'sys', 'taaables';
EXEC dbo.tablecounter 'nope', 'columns';
EXEC dbo.tablecounter null, 'columns';
Select *
FROM dbo.ErrorLog;
our ErrorLog table

Conclusion

I'm a full-stack developer with a passion for programming, technology and traveling. https://www.linkedin.com/in/mikehuls

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store