// error reference

SQL Server error codes

The SQL Server and Azure SQL errors people search for most, each with the exact message text from Microsoft's reference, what it means in plain words, the usual causes and a step-by-step fix with T-SQL.

Reading a SQL Server error

SQL Server prints an error like Msg 2627, Level 14, State 1, Line 3. Msg is the error number (the key to this reference), Level is the severity, State is a sub-code that some errors use to say which of several reasons applied, and Line is the line of the batch that failed.

Severity 10 and below are informational. 11 to 16 are errors the user can correct, such as bad syntax, missing objects or constraint violations. 17 to 19 are resource or software problems that need an administrator. 20 and above are fatal to the connection and are written to the error log.

The %ls and %d markers in a message are placeholders that SQL Server fills with object names and values when it raises the error.

All SQL Server errors in this reference

94 codes, 94 with a full write-up (linked). Codes and messages are from the Microsoft Database Engine events and errors reference.

Connection and login

CodeMeaning
18456 Login failed for user Login failed for user '%.*ls'.%.*ls%.*ls
53 Network-related or instance-specific A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
4060 Cannot open database requested Cannot open database "%.*ls" requested by the login. The login failed.
4064 Cannot open user default database Cannot open user default database. Login failed.
18452 Login is from an untrusted domain Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication.%.*ls
18470 Login failed, account disabled Login failed for user '%.*ls'. Reason: The account is disabled.%.*ls
18486 Login failed, account locked out Login failed for user '%.*ls' because the account is currently locked out. The system administrator can unlock it. %.*ls
18487 Login failed, password expired Login failed for user '%.*ls'. Reason: The password of the account has expired.%.*ls
18488 Login failed, password must be changed Login failed for user '%.*ls'. Reason: The password of the account must be changed.%.*ls
18461 Login failed, single user mode Login failed for user '%.*ls'. Reason: Server is in single user mode. Only one administrator can connect at this time.%.*ls

Permissions

CodeMeaning
916 Login can't access the database The server principal "%.*ls" is not able to access the database "%.*ls" under the current security context.
229 Permission denied on object The %ls permission was denied on the object '%.*ls', database '%.*ls', schema '%.*ls'.
262 Permission denied in database %ls permission denied in database '%.*ls'.
15151 Object doesn't exist or no permission Cannot %S_MSG the %S_MSG '%.*ls', because it does not exist or you do not have permission.
15023 User, group, or role already exists User, group, or role '%s' already exists in the current database.
15025 The server principal already exists The server principal '%s' already exists.
15138 User owns a schema, cannot be dropped The database principal owns a %S_MSG in the database, and cannot be dropped.

Names and objects

CodeMeaning
208 Invalid object name Invalid object name '%.*ls'.
207 Invalid column name Invalid column name '%.*ls'.
4104 Multi-part identifier not bound The multi-part identifier "%.*ls" could not be bound.
209 Ambiguous column name Ambiguous column name '%.*ls'.
2812 Could not find stored procedure Could not find stored procedure '%.*ls'.
2714 There is already an object named There is already an object named '%.*ls' in the database.
3701 Cannot drop, object not found Cannot %S_MSG the %S_MSG '%.*ls', because it does not exist or you do not have permission.
3702 Cannot drop database, currently in use Cannot drop database "%.*ls" because it is currently in use.
5030 Database couldn't be exclusively locked The database %.*ls could not be exclusively locked to perform the operation.
8144 Too many arguments specified Procedure or function %.*ls has too many arguments specified.
8145 Is not a parameter for procedure %.*ls is not a parameter for procedure %.*ls.
8146 Procedure has no parameters Procedure %.*ls has no parameters and arguments were supplied.
4121 Cannot find column or function Cannot find either column "%.*ls" or the user-defined function or aggregate "%.*ls", or the name is ambiguous.
2705 Column names must be unique Column names in each table must be unique. Column name '%.*ls' in table '%.*ls' is specified more than once.
5074 Object is dependent on column The %S_MSG '%.*ls' is dependent on %S_MSG '%.*ls'.
4922 Objects access this column %ls %.*ls failed because one or more objects access this %S_MSG.
7202 Could not find server in sys.servers Could not find server '%.*ls' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
2760 Schema does not exist or no permission The specified schema name "%.*ls" either does not exist or you do not have permission to use it.
8178 Parameterized query expects a parameter The parameterized query '%.*ls' expects the parameter '%.*ls', which was not supplied.

Syntax and compilation

CodeMeaning
102 Incorrect syntax near Incorrect syntax near '%.*ls'.
156 Incorrect syntax near the keyword Incorrect syntax near the keyword '%.*ls'.
105 Unclosed quotation mark after the string Unclosed quotation mark after the character string '%.*ls'.
4145 Non-boolean expression in a condition An expression of non-boolean type specified in a context where a condition is expected, near '%.*ls'.
8120 Column not in GROUP BY or aggregate Column '%.*ls.%.*ls' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
8118 Aggregate without GROUP BY Column '%.*ls.%.*ls' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.
8672 MERGE touched the same row twice The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than one source row. A MERGE statement cannot UPDATE/DELETE the same row of the target table multiple times. Refine the ON clause to ensure a target row matches at most one source row, or use the GROUP BY clause to group the source rows.
1934 SET options have incorrect settings %ls failed because the following SET options have incorrect settings: '%.*ls'. Verify that SET options are correct for use with %S_MSG.

Constraints and keys

CodeMeaning
2627 Violation of PRIMARY KEY or UNIQUE KEY Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'. The duplicate key value is %ls.
2601 Cannot insert duplicate key row Cannot insert duplicate key row in object '%.*ls' with unique index '%.*ls'. The duplicate key value is %ls.
547 Statement conflicted with a constraint The %ls statement conflicted with the %ls constraint "%.*ls". The conflict occurred in database "%.*ls", table "%.*ls"%ls%.*ls%ls.
515 Cannot insert the value NULL into column Cannot insert the value NULL into column '%.*ls', table '%.*ls'; column does not allow nulls. %ls fails.
3726 Can't drop: referenced by a FOREIGN KEY Could not drop object '%.*ls' because it is referenced by a FOREIGN KEY constraint.
1913 Index or statistics name already exists The operation failed because an index or statistics with name '%.*ls' already exists on %S_MSG '%.*ls'.
1750 Could not create constraint or index Could not create constraint or index. See previous errors.
4712 Can't truncate a referenced table Cannot truncate table '%.*ls' because it is being referenced by a FOREIGN KEY constraint.
1505 Duplicate key found, unique index The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name '%.*ls' and the index name '%.*ls'. The duplicate key value is %ls.

Data conversion and truncation

CodeMeaning
8152 String or binary data truncated String or binary data would be truncated.
2628 Truncated in table, column String or binary data would be truncated in table '%.*ls', column '%.*ls'. Truncated value: '%.*ls'.
245 Conversion failed converting a value Conversion failed when converting the %ls value '%.*ls' to data type %ls.
241 Conversion failed for date and/or time Conversion failed when converting date and/or time from character string.
242 Out-of-range date conversion The conversion of a %ls data type to a %ls data type resulted in an out-of-range value.
8115 Arithmetic overflow error converting Arithmetic overflow error converting %ls to data type %ls.
8114 Error converting data type Error converting data type %ls to %ls.
512 Subquery returned more than 1 value Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
8134 Divide by zero error encountered Divide by zero error encountered.
220 Arithmetic overflow error for data type Arithmetic overflow error for data type %ls, value = %ld.
248 Conversion overflowed an int column The conversion of the %ls value '%.*ls' overflowed an int column.
8169 Conversion to uniqueidentifier failed Conversion failed when converting from a character string to uniqueidentifier.
8117 Operand data type invalid for operator Operand data type %ls is invalid for %ls operator.

Transactions and locking

CodeMeaning
266 Transaction count mismatch after EXECUTE Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = %ld, current count = %ld.
1205 Deadlocked and chosen as the victim Transaction (Process ID %d) was deadlocked on %.*ls resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
1222 Lock request time out period exceeded Lock request time out period exceeded.
3930 Transaction cannot be committed The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
3902 COMMIT has no corresponding BEGIN The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
3903 ROLLBACK has no corresponding BEGIN The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
3609 Transaction ended in the trigger The transaction ended in the trigger. The batch has been aborted.
3960 Snapshot isolation update conflict Snapshot isolation transaction aborted due to update conflict. You cannot use snapshot isolation to access table '%.*ls' directly or indirectly in database '%.*ls' to update, delete, or insert the row that has been modified or deleted by another transaction. Retry the transaction or change the isolation level for the update/delete statement.
3616 Error raised during trigger execution An error was raised during trigger execution. The batch has been aborted and the user transaction, if any, has been rolled back.
6401 No transaction or savepoint found Cannot roll back %.*ls. No transaction or savepoint of that name was found.
3998 Uncommittable transaction rolled back Uncommittable transaction is detected at the end of the batch. The transaction is rolled back.
3621 The statement has been terminated The statement has been terminated.

Memory, log and storage

CodeMeaning
9002 Transaction log for database is full The transaction log for database '%ls' is full due to '%ls' and the holdup lsn is %S_LSN.
1105 Filegroup is full, cannot allocate Could not allocate space for object '%.*ls'%.*ls in database '%.*ls' because the '%.*ls' filegroup is full due to lack of storage space or database files reaching the maximum allowed size. Note that UNLIMITED files are still limited to 16TB. Create the necessary space by dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
1101 Could not allocate a new page Could not allocate a new page for database '%.*ls' because the '%.*ls' filegroup is full due to lack of storage space or database files reaching the maximum allowed size. Note that UNLIMITED files are still limited to 16TB. Create the necessary space by dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
701 Insufficient memory in resource pool There is insufficient system memory in resource pool '%ls' to run this query.
8645 Timeout waiting for memory resources A timeout occurred while waiting for memory resources to execute the query in resource pool '%ls' (%ld). Rerun the query.
8623 Query processor ran out of resources The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.
1204 Cannot obtain a LOCK resource The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions.

Backup and restore

CodeMeaning
3013 BACKUP or RESTORE ended abnormally %hs is terminating abnormally.
3154 Backup set is of a different database The backup set holds a backup of a database other than the existing '%ls' database.
3201 Cannot open backup device Cannot open backup device '%ls'. Operating system error %ls.
5120 Unable to open the physical file Unable to open the physical file "%.*ls". Operating system error %d: "%ls".
3101 Exclusive access could not be obtained Exclusive access could not be obtained because the database is in use.

Corruption and I/O

CodeMeaning
824 Logical consistency-based I/O error 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.
823 Operating system returned an I/O error 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.
825 Read retry succeeded after failing 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.
9001 The log for database is not available The log for database '%.*ls' is not available. Check the operating system error log for related error messages. Resolve any errors and restart the database.
// one client, every engine

A faster way to work with SQL Server

SQLly is a native SQL client for macOS, Windows and Linux with schema-aware IntelliSense and guardrails for risky statements.