SQL Server Error Reference

1 model · 15 error codes

Browse SQL Server error code collections, meanings, and related context across the current corpus.

About SQL Server Error Reference

SQL Server is a relational database engine that reports errors through a combination of an error number, a severity level (0–25), and a state value. Errors surface to users through several channels: SQL Server Management Studio (SSMS) message panels, application connection strings, T-SQL TRY/CATCH blocks, and the SQL Server error log. The sys.messages catalog in the master database stores the text for every engine-defined error code, and administrators can query it to look up unfamiliar error numbers.

SQL Server errors are raised through multiple mechanisms. The engine itself raises errors for constraint violations, deadlocks, and resource exhaustion. Application code can raise custom errors using RAISERROR or THROW. The T-SQL TRY/CATCH construct lets developers catch errors programmatically and inspect them through the ERROR_NUMBER(), ERROR_SEVERITY(), and ERROR_MESSAGE() functions. When a connection-level failure occurs (like error 18456, login failed), the client receives the error before any T-SQL can execute, so TRY/CATCH cannot intercept it.

FixerCode documents 15 SQL Server engine errors across 1 model, covering constraint violations, deadlocks, login failures, permission errors, and database-level faults. Each entry identifies the error number, its severity classification, the database operation that typically triggers it, and whether the error is catchable in T-SQL.

Select Your Model 1

Frequently Asked Questions

SQL Server stores all engine-defined error messages in the sys.messages catalog view in the master database. You can query it with SELECT * FROM sys.messages WHERE message_id = 2627 to look up a specific error. The catalog includes the message text, severity level, and language ID for every system-defined error.

Use a BEGIN TRY / BEGIN CATCH block. Inside the CATCH block, the ERROR_NUMBER() function returns the error number, ERROR_SEVERITY() returns the severity level, and ERROR_MESSAGE() returns the message text. Note that connection-level failures like error 18456 (login failed) cannot be caught this way because the error occurs before any T-SQL batch executes.

Yes. Use RAISERROR or THROW to raise custom errors with a user-defined error number (above 50000) and a severity level. THROW is the newer syntax introduced in SQL Server 2012 and automatically rolls back the transaction, while RAISERROR gives more control over formatting but does not automatically roll back.