sql server / error codes

SQL Server error codes

SQL Server error codes are numbered Database Engine messages that describe a condition or failure. Search the code to find its message and severity, then check the error log and state for the runtime cause.

Error codes

17,269

Database Engine error numbers

Event logged

1,429

Marked by SQL Server for Windows event logging

Microsoft pages

344

Errors with a dedicated source page

Data checked

Jul 13, 2026

73,392 source rows parsed

Check error messages on your SQL Server instance

sys.messages contains one row for each installed message ID and language. Message IDs below 50,000 are system messages. Language ID 1033 is US English; use an installed language ID when you need other text.

Returns the local error number, severity, event-log flag, and message text.

SQL

List installed SQL Server messages

T-SQL · 8 lines

SELECT    message_id AS error_number,    severity,    is_event_logged,    [text] AS message_textFROM sys.messagesWHERE language_id = 1033ORDER BY message_id;
Review before runningT-SQLUTF-88 lines

Change 18456 to the error number you need.

SQL

Look up one SQL Server error number

T-SQL · 10 lines

DECLARE @error_number int = 18456; SELECT    message_id AS error_number,    severity,    is_event_logged,    [text] AS message_textFROM sys.messagesWHERE language_id = 1033  AND message_id = @error_number;
Review before runningT-SQLUTF-810 lines

Source: Microsoft sys.messages documentation. The view is available to the public database role, subject to metadata visibility.

How SQL Server error number, severity and state differ

The error number identifies the message family. Severity classifies the type of problem. State adds error-specific context about where or why the message was raised. There is no one state table that applies to every error number.

0-10Informational messages or status information that is not severe.Read the context and confirm whether the operation actually failed.
11-16Errors commonly tied to objects, deadlocks, security, syntax, or other user-correctable conditions.Capture the statement, caller, database, and exact message before changing code or permissions.
17-19Resource, software, or internal conditions that need administrator review.Check the affected resource and SQL Server error log. Severity 19 and higher is written to the error log.
20-24Fatal task, process, database, media, or hardware-related conditions.Preserve the logs, identify the affected database or file, and treat the incident as urgent.

State is code-specific

Error 18456 states describe login-failure reasons. A state value on another error can mean something completely different.

Event logged is a catalog flag

The is_event_logged bit marks messages written to the Windows application log when raised. The SQL Server error log can hold more surrounding engine detail.

Source: Microsoft Database Engine error severities.

Common SQL Server errors and the first check

These answers add a DBA-reviewed first check to the Microsoft catalog message. Use the search above for every other code in the current 17,269-error snapshot.

SQL Server error 18456

SQL Server error 18456: Login failed for user

SQL Server rejected a login attempt. The client message hides the exact authentication reason, so the state in the matching SQL Server error-log entry is the useful diagnostic detail.

Severity 14Event logged Yes

Catalog message

Login failed for user '%.*ls'.%.*ls%.*ls

Check this first

Find the error-log entry at the same timestamp and read the login name, state, client address, and reason text. Then confirm that the application reached the intended instance and database.

Common cause groups

  • The login name or password is wrong, disabled, expired, or marked for a password change.
  • The client is using SQL authentication against a Windows-only instance, or is using a Windows login name as a SQL login.
  • The login is valid but lacks server access or cannot open its default or requested database.
  • Windows authentication failed because of domain, group, SPN, delegation, or SID context.
StateMicrosoft description in plain language
2 or 5The user ID is not valid.
6A Windows login name was used with SQL Server Authentication.
7The login is disabled and the password is incorrect.
8The password is incorrect.
11 or 12The login is valid, but server access failed.
18The password must be changed.
38 or 46SQL Server could not find or open the database requested by the user.
58A SQL login reached a Windows-only instance, or the security identifiers do not match.
Avoid this assumption: The text returned to the client is deliberately vague. Resetting passwords or granting broad access before checking the server-side state can hide the real cause and create a security problem.

The result should include the state and reason that the client message omits.

SQL

Find error 18456 in the SQL Server error log

T-SQL · 10 lines

-- Search the current SQL Server error log for login failures.-- Reading the error log normally needs elevated server permissions.EXEC master.dbo.xp_readerrorlog    0,    1,    N'Error: 18456',    NULL,    NULL,    NULL,    N'desc';
Review before runningT-SQLUTF-810 lines

xp_readerrorlog is useful for an administrator's targeted log review. Access normally needs elevated server permissions.

SQL Server error 9002

SQL Server error 9002: The transaction log is full

SQL Server cannot reuse or extend enough transaction-log space for the current work. The reported reason and sys.databases.log_reuse_wait_desc determine the next check.

Severity 17Event logged Yes

Catalog message

The transaction log for database '%ls' is full due to '%ls' and the holdup lsn is %S_LSN.

Check this first

Check log_reuse_wait_desc, current log use, the file's configured maximum size, free space on the volume, the recovery model, and the last successful log backup before changing file size.

Common cause groups

  • A log backup is required, or a long-running transaction is holding active log records.
  • The disk is full, the log reached its maximum size, or autogrowth cannot complete.
  • Replication, change data capture, mirroring, or an availability replica is delaying log truncation.
  • Recovery, backup, restore, or another engine operation is temporarily holding the log.
Avoid this assumption: Shrinking the log does not remove the reason it became full. Find the reuse wait first, preserve the backup chain, and avoid adding extra log files as a routine fix.

Replace YourDatabase with the affected database. Both queries read current catalog and log-space information.

SQL

Check why the transaction log cannot be reused

T-SQL · 15 lines

-- Check why log space cannot currently be reused.SELECT    name AS database_name,    recovery_model_desc,    log_reuse_wait_descFROM sys.databasesWHERE name = N'YourDatabase'; -- Run this second query in the affected database.USE [YourDatabase];SELECT    total_log_size_in_bytes / 1024.0 / 1024.0 AS total_log_mb,    used_log_space_in_bytes / 1024.0 / 1024.0 AS used_log_mb,    used_log_space_in_percentFROM sys.dm_db_log_space_usage;
Review before runningT-SQLUTF-815 lines

sys.dm_db_log_space_usage can require VIEW DATABASE STATE or the equivalent permission for the SQL Server version in use.

SQL Server error 1205

SQL Server error 1205: Transaction was chosen as the deadlock victim

Two or more transactions formed a lock cycle, and SQL Server rolled back one transaction so the others could continue. Error 1205 names the victim; the deadlock graph shows the statements, objects, indexes, and lock modes involved.

Severity 13Event logged No

Catalog message

Transaction (Process ID %d) was deadlocked on %.*ls resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

Check this first

Pull the deadlock XML from system_health and map every process in the graph to its application action. Review object access order, transaction scope, execution plans, and retry behavior together.

Common cause groups

  • Different transactions access the same objects in a conflicting order.
  • A wide scan, missing access path, or plan change holds more locks for longer.
  • Transactions stay open around application work that does not need to be inside the transaction.
  • Isolation and concurrency patterns make the same resources collide repeatedly.
Avoid this assumption: The victim statement is not automatically the cause. A bounded retry can handle a transient victim, but the graph is still needed when the pattern repeats.

The built-in system_health session captures deadlock XML on supported SQL Server versions.

SQL

Read recent deadlock graphs from system_health

T-SQL · 16 lines

-- Read recent deadlock graphs from the built-in system_health session.SELECT TOP (20)    xdr.value('@timestamp', 'datetime2') AS deadlock_time,    xdr.query('(data/value/deadlock)[1]') AS deadlock_xmlFROM (    SELECT CAST(target_data AS xml) AS target_data    FROM sys.dm_xe_session_targets AS xt    JOIN sys.dm_xe_sessions AS xs        ON xs.address = xt.event_session_address    WHERE xs.name = N'system_health'      AND xt.target_name = N'ring_buffer') AS rbCROSS APPLY rb.target_data.nodes(    'RingBufferTarget/event[@name="xml_deadlock_report"]') AS XEventData(xdr)ORDER BY deadlock_time DESC;
Review before runningT-SQLUTF-816 lines

Reading server Extended Events targets requires server-level visibility permissions that vary by SQL Server version.

SQL Server errors 823, 824 and 825 compared

All three messages point to the I/O path, but they describe different observations. Error 823 is an operating-system I/O failure. Error 824 is a logical consistency failure after Windows reported success. Error 825 means a read worked only after retrying.

ErrorWhat SQL Server observedWhy it mattersFirst evidence
823A Windows I/O API returned an operating-system error to SQL Server.The storage or operating-system path could not complete the read or write request.SQL Server error log, Windows System log, OS error code, file, offset, and operation.
824Windows reported a successful transfer, but SQL Server found a logical page-consistency problem.The page content, file system, driver, firmware, or storage path failed SQL Server's consistency checks.Error log, msdb.dbo.suspect_pages, DBCC CHECKDB output, file, page, and affected volume.
825A read succeeded only after SQL Server retried it one or more times.The immediate query survived, but the storage path may still cause data loss or corruption.SQL Server error log, Windows System log, disk, controller, array, and driver diagnostics.

Error 823

The operating system returned error %ls to SQL Server during a %S_MSG at offset %#016I64x in file '%ls'. Additional messages in the SQL Server error log and operating system error log may provide more detail. This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.

Error 824

SQL Server detected a logical consistency-based I/O error: %ls. It occurred during a %S_MSG of page %S_PGID in database ID %d at offset %#016I64x in file '%ls'. Additional messages in the SQL Server error log or operating system error log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see [https://go.microsoft.com/fwlink/?linkid=2252374](https://go.microsoft.com/fwlink/?linkid=2252374).

Error 825

A read of the file '%ls' at offset %#016I64x succeeded after failing %d time(s) with error: %ls. Additional messages in the SQL Server error log and operating system error log may provide more detail. This error condition threatens database integrity and must be corrected. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.

Treat all three as serious. Preserve the SQL Server and Windows log entries, identify the database, file, page or offset, and involve the storage or infrastructure owner. Plan DBCC CHECKDB around database size and production load. A successful retry does not make error 825 harmless, and REPAIR_ALLOW_DATA_LOSS is not a routine first response.

These reads help correlate the error number with database-page and log details. Error-log access normally needs elevated server permissions.

SQL

Check suspect pages and the SQL Server error log

T-SQL · 15 lines

-- Find recent suspect-page records across databases.SELECT TOP (100)    DB_NAME(database_id) AS database_name,    file_id,    page_id,    event_type,    error_count,    last_update_dateFROM msdb.dbo.suspect_pagesORDER BY last_update_date DESC; -- Search the current SQL Server error log for one code at a time.EXEC master.dbo.xp_readerrorlog 0, 1, N'Error: 823', NULL, NULL, NULL, N'desc';EXEC master.dbo.xp_readerrorlog 0, 1, N'Error: 824', NULL, NULL, NULL, N'desc';EXEC master.dbo.xp_readerrorlog 0, 1, N'Error: 825', NULL, NULL, NULL, N'desc';
Review before runningT-SQLUTF-815 lines

SQL Server error 2627

SQL Server error 2627: Duplicate key violated a unique constraint

An INSERT or UPDATE produced a key value that already exists under a primary-key or unique constraint. The message normally names the constraint, object, and duplicate key value.

Severity 14Event logged No

Catalog message

Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'. The duplicate key value is %ls.

Check this first

Capture the full message and the submitted values. Find the named constraint or unique index, then check whether the request is a duplicate submission, an application race, an identity-range problem, or an expected upsert path.

Common cause groups

  • The same business request or source row was submitted twice.
  • Concurrent sessions checked for a row and then both tried to insert it.
  • Identity or key ranges overlap across import, replication, or distributed writers.
  • The application's conflict-handling path does not match the database uniqueness rule.
Avoid this assumption: Dropping or weakening the unique constraint can turn a handled error into duplicate data. Confirm whether the key rule is correct before changing schema or application logic.

SQL Server error 208

SQL Server error 208: Invalid object name

SQL Server could not resolve the table, view, synonym, or other referenced object in the statement's current database and schema context.

Severity 16Event logged No

Catalog message

Invalid object name '%.*ls'.

Check this first

Capture the exact submitted SQL and verify the connected server, database, schema, and object name. Then check deployment state, case sensitivity, temporary-table scope, and metadata visibility for the executing principal.

Common cause groups

  • The connection is using the wrong database or the object name lacks the intended schema.
  • The object was renamed, dropped, or was not created by the expected deployment.
  • The name has the wrong case under a case-sensitive database collation.
  • A temporary object is outside its scope, or the caller cannot see the object's metadata.

SQL Server error 229

SQL Server error 229: Permission was denied

The current execution context lacks the named permission on the object, schema, or database reported in the message.

Severity 14Event logged No

Catalog message

The %ls permission was denied on the object '%.*ls', database '%.*ls', schema '%.*ls'.

Check this first

Record the login, database user, database, object, permission name, application, and module that raised the error. Check direct grants and denies, role membership, ownership chaining, impersonation, and module signing before adding access.

Common cause groups

  • The login is not mapped to the expected database user or role.
  • An explicit DENY overrides access inherited through another role or group.
  • The code runs under a different execution context than the caller expects.
  • A deployment created the object but did not apply the matching permission.
Avoid this assumption: Grant the smallest permission needed for the operation. Adding db_owner or sysadmin to remove one denial creates a much larger security problem.

SQL Server error 245

SQL Server error 245: Conversion failed for a value

SQL Server tried to convert a value to another data type and at least one input could not be represented in the target type.

Severity 16Event logged No

Catalog message

Conversion failed when converting the %ls value '%.*ls' to data type %ls.

Check this first

Capture the exact value, source column or parameter, target type, and full expression. Check implicit conversions introduced by joins, CASE expressions, UNION branches, comparisons, and parameter types.

Common cause groups

  • Text contains a value that is not valid for the requested numeric, date, or other target type.
  • Data-type precedence makes SQL Server convert the unexpected side of an expression.
  • A CASE or UNION mixes incompatible types across branches.
  • An application parameter type does not match the SQL column or procedure definition.
Avoid this assumption: A broad TRY_CONVERT wrapper can hide bad source data. Find which row and expression failed before deciding whether invalid values should be rejected, cleaned, or handled explicitly.

SQL Server error 207

SQL Server error 207: Invalid column name

SQL Server could not bind a referenced column name while compiling the statement. The name, database schema, alias scope, or deployed object definition does not match the submitted SQL.

Severity 16Event logged No

Catalog message

Invalid column name '%.*ls'.

Check this first

Capture the exact batch, connected database, and object definition. Verify spelling and case, then check deployment order and whether a SELECT-list alias is being referenced before that alias is available.

Common cause groups

  • The column was misspelled, renamed, removed, or was not deployed.
  • The database uses a case-sensitive collation and the letter case differs.
  • A SELECT-list alias is referenced in a clause where logical processing has not defined it yet.
  • Dynamic SQL or application-generated SQL uses a different schema version.

SQL Server error 102

SQL Server error 102: Incorrect syntax near a token

SQL Server could not parse the submitted T-SQL batch. The token named in the message is where parsing stopped, which can be after the original missing comma, quote, bracket, alias, or keyword.

Severity 15Event logged No

Catalog message

Incorrect syntax near '%.*ls'.

Check this first

Capture the exact SQL sent to the server, including generated dynamic SQL and parameter placeholders. Check the text immediately before the named token and compare the syntax with the target SQL Server version and compatibility level.

Common cause groups

  • A quote, comma, parenthesis, bracket, alias, or keyword is missing or misplaced.
  • Dynamic SQL joined fragments without the required whitespace or punctuation.
  • The statement uses syntax unavailable on the target SQL Server version or compatibility level.
  • Application logging shows a template instead of the final submitted batch.
Avoid this assumption: The token named in error 102 is often the first place the parser could no longer continue, not the location where the mistake began.

Where to find the full SQL Server error detail

The catalog explains the message template. The actual occurrence needs its timestamp and caller context.

  1. 01

    Application or job output

    Capture the complete exception, failed job step, submitted statement, parameters, server, and database.

  2. 02

    SQL Server error log

    Match the timestamp and error number. Read the lines before and after it for state, file, database, login, or engine context.

  3. 03

    Windows Application and System logs

    Correlate service, storage, driver, cluster, and operating-system events from the same window.

  4. 04

    Extended Events

    Use error_reported, deadlock, or a focused session when the event is repeatable and the ordinary logs omit caller detail.

  5. 05

    Database and session context

    Record the login, database user, application name, host, session, transaction, and database state.

  6. 06

    Recent change record

    Check deployments, permission changes, failovers, patches, storage events, and job timing around the first occurrence.

SQL Server error categories

These are site-created navigation groups, not an official Microsoft error taxonomy. Use them when you know the type of problem but not the exact code.

General engine error

7,346 errors

Database Engine messages that do not fit one of the narrower navigation groups.

Examples #165 #184 #187 #192

Syntax or query shape

2,325 errors

T-SQL parsing, object, column, variable, identifier, procedure, and function messages.

Examples #208 #207 #102 #101

Security or permissions

1,698 errors

Login, access, credential, certificate, principal, user, and permission messages.

Examples #18456 #2627 #229 #218

Availability

1,355 errors

Messages mentioning replicas, failover, endpoints, mirroring, clustering, listeners, or Always On state.

Examples #341 #369 #548 #666

Resource pressure

1,206 errors

Messages involving disk, log space, tempdb, memory, workers, quotas, or configured limits.

Examples #9002 #103 #105 #106

Performance or concurrency

1,041 errors

Messages involving locks, blocking, query execution, workers, waits, plans, or concurrency.

Examples #159 #172 #288 #304

Version or change risk

875 errors

Version, compatibility, edition, deprecated behavior, and feature-support messages.

Examples #245 #125 #206 #210

Corruption or engine risk

749 errors

High-severity I/O, checksum, consistency, DBCC, and storage-related messages.

Examples #823 #824 #825 #21

Backup and restore

664 errors

Messages involving backup, restore, recovery, media, files, or the backup chain.

Examples #667 #805 #908 #922

Deadlock

10 errors

Messages raised when sessions form a lock cycle and SQL Server chooses a victim.

Examples #1205 #1231 #3635 #5231

SQL Server error number ranges

Microsoft publishes the Database Engine catalog in number ranges. Open the matching range when a code has no dedicated Microsoft page.

25 ranges

An error code is the start of the diagnosis

Start with the catalog message

The error number identifies the Microsoft Database Engine message. This reference covers SQL Server 2016 through 2025 and was last checked Jul 13, 2026.

Add the runtime details

Capture the state, timestamp, database, object or file name, failing statement, and nearby SQL Server error-log entries. Those values narrow the cause behind the message template.

Confirm the cause before changing anything

Use the first checks to collect logs and run read-only queries. Confirm what failed before changing permissions, database files, server settings, or storage.

If the same error keeps returning and the cause is still unclear, send the full message, timestamp, SQL Server version, surrounding log lines, and what changed recently.

SQL Server error-code questions

How do I find the text for a SQL Server error number?

Search this page by number or query the sys.messages catalog view on the affected SQL Server instance. The local catalog is useful when the installed build or message language matters.

What is the difference between SQL Server error severity and state?

Severity classifies the type or seriousness of the condition. State gives extra context for a particular error and is specific to that error number. Error 18456, for example, uses state to narrow the login-failure reason.

Where is the SQL Server error log?

In SQL Server Management Studio, open Management, SQL Server Logs, then Current. Administrators can also use documented management tools or targeted error-log procedures to read matching entries.

What does event logged mean for a SQL Server error?

The sys.messages is_event_logged value marks whether SQL Server writes the message to the Microsoft Windows application log when it is raised. Check the SQL Server error log as well because it often contains the surrounding engine detail.

Why can one SQL Server error number show different details?

Catalog messages contain placeholders that SQL Server fills at runtime with names, values, files, databases, or operating-system details. Message text can also vary by installed language and SQL Server version.

Is every SQL Server connection failure error 18456?

Error 18456 means the connection reached SQL Server and authentication was rejected. Errors 26, 40, 53, and login timeouts usually point to instance discovery, the SQL Server service, name resolution, protocols, ports, TLS, or firewall rules. Test locally first, then check the SQL Server error log and the 18456 state when authentication is involved.

Is a query timeout a SQL Server Database Engine error?

A query timeout is raised by the client when a command exceeds its configured limit. SQL Server may record an Attention event and error 3617 after the cancellation. Separate it from a connection timeout, then inspect the slow query, blocking, waits, execution plan, and application settings.

How should recurring SQL Server errors be monitored?

Use the SQL Server error log and Windows Application and System logs for server events, SQL Server Agent alerts for selected severities or messages, and Extended Events for problems that need statement or session detail. A centralized monitoring tool helps when several instances need shared retention, filtering, and alert routing.