Skip to content

SQL Server Error Library

Look up any SQL Server error by number: the cause, examples, fixes and prevention.

Common errors 21

2627 Violation of PRIMARY KEY / UNIQUE constraintCannot insert a duplicate key into a primary key or unique constraint. 547 Statement conflicted with a FOREIGN KEY or CHECK constraintAn insert, update or delete broke a foreign key or check rule. 18456 Login failed for userAuthentication failed; the state number reveals the real reason. 4060 Cannot open database requested by the loginThe requested database is missing, offline or off-limits to the login. 53 A network-related or instance-specific error (server not found)The client could not reach a listening SQL Server instance. 26 Error locating server or instance specified (SQL Network Interfaces)The client could not resolve the named instance (SQL Server Browser, UDP 1434, wrong name). 207 Invalid column nameThe query references a column that does not exist in scope. 208 Invalid object nameThe table, view or object cannot be resolved. 4104 The multi-part identifier could not be boundA table or alias prefix such as c.name does not match anything in the FROM clause. 209 Ambiguous column nameAn unqualified column name matches more than one table in the query. 8120 Column is invalid in the select list because it is not in an aggregate or GROUP BYA grouped query selects a column that is neither grouped nor aggregated. 137 Must declare the scalar variableA variable is used outside the batch or scope that declares it (GO, dynamic SQL). 245 Conversion failed converting varchar value to intA text value could not be converted to a number. 8152 String or binary data would be truncatedA value was too long for the column; the bare message used at compatibility level 140 or lower. 241 Conversion failed when converting date and/or time from character stringText could not be read as a date: placeholders, impossible dates or text + datetime. 1205 Transaction was deadlocked and chosen as the victimTwo transactions blocked each other; one was rolled back to break the cycle. 9002 The transaction log for database is fullThe log file cannot grow or reuse space, so writes stop. 3201 Cannot open backup device (operating system error)BACKUP or RESTORE could not open the file; the OS error says why (path, permission, device). 3154 The backup set holds a backup of a database other than the existing databaseRESTORE refused to overwrite an existing database that the backup was not taken from. 3159 The tail of the log for the database has not been backed upRestoring over a FULL recovery database would lose changes since the last log backup. 3013 BACKUP DATABASE / RESTORE DATABASE is terminating abnormallyThe closing line of every failed BACKUP or RESTORE; the real cause is the error printed just before it.

Logins & Permissions 19

18456 Login failed for userAuthentication failed; the state number reveals the real reason. 4060 Cannot open database requested by the loginThe requested database is missing, offline or off-limits to the login. 4064 Cannot open user default databaseThe login default database cannot be opened, so the connection fails. 229 The permission was denied on the objectThe user lacks SELECT, EXECUTE or another object-level permission. 262 Permission denied, unable to run a statementThe user cannot run CREATE, ALTER or another statement-level command. 15247 User does not have permission to perform this actionA security statement such as CREATE USER, CREATE ROLE or CREATE SCHEMA needs a permission the user lacks. 18452 Login failed: the login is from an untrusted domainWindows credentials could not be validated: untrusted domain, SPN or Kerberos/NTLM failure. 916 The server principal is not able to access the database under the current security contextThe login or impersonated user has no user (and no guest access) in the target database. 300 Permission was denied on object (for example VIEW SERVER STATE)A login lacks VIEW SERVER STATE or another permission a DMV or tool checks. 15023 User, group or role already exists in the current databaseThe user or role name is taken, often by an orphaned user after a restore. 15138 The database principal owns a schema and cannot be droppedDROP USER or DROP ROLE fails because the principal still owns a schema; transfer it with ALTER AUTHORIZATION. 15151 Cannot find the login or user because it does not exist or you do not have permissionA user, login, role or schema name was not found in this scope, or the caller lacks permission to change it. 15434 Could not drop login as the user is currently logged inDROP LOGIN is refused while any session (including pooled connections) uses the login. 18461 Login failed: server is in single user modeThe instance was started with -m and its only connection is already taken. 18470 Login failed: the account is disabledThe password was correct but the login is disabled. 18486 Login failed because the account is currently locked outA SQL login was locked by the Windows lockout policy after too many wrong passwords. 18487 Login failed: the password of the account has expiredA SQL login with CHECK_EXPIRATION has a password older than the maximum password age. 18488 Login failed: the password of the account must be changedThe login is flagged MUST_CHANGE and must set a new password before it can connect. 17809 Could not connect because the maximum number of user connections has been reachedA new connection was refused because the instance holds as many user connections as it allows; look for connection leaks first.

Syntax & Object Resolution 22

102 Incorrect syntax nearThe parser hit an unexpected token in your T-SQL. 156 Incorrect syntax near the keywordA reserved keyword was used or placed where it is not allowed. 207 Invalid column nameThe query references a column that does not exist in scope. 208 Invalid object nameThe table, view or object cannot be resolved. 201 Procedure or function expects a parameter which was not suppliedA required stored procedure parameter was not passed. 4104 The multi-part identifier could not be boundA table or alias prefix such as c.name does not match anything in the FROM clause. 3701 Cannot drop the object because it does not exist or no permissionA DROP failed on a missing object or without the right permission. 209 Ambiguous column nameAn unqualified column name matches more than one table in the query. 8120 Column is invalid in the select list because it is not in an aggregate or GROUP BYA grouped query selects a column that is neither grouped nor aggregated. 105 Unclosed quotation mark after the character stringA string literal was opened but never closed, usually followed by error 102. 137 Must declare the scalar variableA variable is used outside the batch or scope that declares it (GO, dynamic SQL). 2714 There is already an object named in the databaseA CREATE or SELECT INTO uses a name already taken by a table, constraint or module. 213 Column name or number of supplied values does not match table definitionAn INSERT without a column list supplies the wrong number of values. 544 Cannot insert explicit value for identity column when IDENTITY_INSERT is OFFAn INSERT lists the identity column but IDENTITY_INSERT is not ON in this scope. 8101 An explicit value for the identity column can only be specified with a column list and IDENTITY_INSERT ONAn INSERT without a column list supplies a value for the identity column. 2812 Could not find stored procedureEXEC names a procedure that does not exist in that schema or database. 134 The variable name has already been declaredThe same @variable is declared twice in one batch or procedure; loops and IF blocks are not separate scopes. 2760 The specified schema name either does not exist or you do not have permissionA CREATE or SELECT INTO names a schema that is missing or that the user cannot ALTER. 4121 Cannot find either column or the user-defined function or aggregateA prefix.Name(...) call matched no function in that schema: wrong schema, alias as prefix, or an xml method on text. 4145 An expression of non-boolean type specified where a condition is expectedWHERE, IF or CASE WHEN got a value such as a bit column instead of a comparison. 4902 Cannot find the object because it does not exist or you do not have permissionsALTER TABLE names a table that does not resolve: a typo, the wrong schema, or a temp table from an ended scope. 1919 Column is of a type that is invalid for use as a key column in an indexA (max), text or image column was used as an index or constraint key; use INCLUDE, a hash or prefix column, or a shorter type.

Data Type & Conversion 15

245 Conversion failed converting varchar value to intA text value could not be converted to a number. 8114 Error converting data type X to YA value could not be converted to numeric, decimal, float or bigint, often through a procedure parameter. 8115 Arithmetic overflow converting expression to data typeA value was too large for the target numeric type. 8134 Divide by zero error encounteredAn expression divided by zero. 512 Subquery returned more than 1 valueA scalar subquery returned more than one row. 8152 String or binary data would be truncatedA value was too long for the column; the bare message used at compatibility level 140 or lower. 2628 String or binary data would be truncated (named column)The detailed truncation message (compatibility level 150 or higher) naming the table, column and truncated value. 241 Conversion failed when converting date and/or time from character stringText could not be read as a date: placeholders, impossible dates or text + datetime. 242 The conversion of a varchar data type to a datetime data type resulted in an out-of-range valueDay and month read in the wrong order (DATEFORMAT/language) or a date outside the datetime range. 220 Arithmetic overflow error for data type, valueA value did not fit tinyint or smallint; the message shows the value. 468 Cannot resolve the collation conflictTwo text columns with different collations were compared, joined or combined in a UNION. 206 Operand type clashTwo types with no implicit conversion met: int into a date column, datetime2 + 1, or the wrong table type for a TVP. 402 The data types are incompatible in the operatorAn operator such as = or + got types it cannot combine: text/ntext/xml compared with a string, or a string + uniqueidentifier. 8116 Argument data type is invalid for argument of functionA built-in function got the wrong type in one argument, such as SUBSTRING on an int or DATEADD with a varchar number. 8169 Conversion failed when converting from a character string to uniqueidentifierText that is not a valid GUID (a placeholder, an empty string, missing hyphens) was converted to uniqueidentifier.

Backup & Restore 15

3201 Cannot open backup device (operating system error)BACKUP or RESTORE could not open the file; the OS error says why (path, permission, device). 3241 The media family on device is incorrectly formedThe restore file is not a readable backup: not a backup, cut short in transit, or an unreadable format. 3154 The backup set holds a backup of a database other than the existing databaseRESTORE refused to overwrite an existing database that the backup was not taken from. 3159 The tail of the log for the database has not been backed upRestoring over a FULL recovery database would lose changes since the last log backup. 3101 Exclusive access could not be obtained because the database is in useRESTORE needs the database to itself but other sessions are still connected. 3169 The database was backed up on a server running an incompatible versionThe backup comes from a newer SQL Server version and cannot be restored on this one. 4214 BACKUP LOG cannot be performed because there is no current database backupA log backup was attempted before a full backup started the log chain. 3013 BACKUP DATABASE / RESTORE DATABASE is terminating abnormallyThe closing line of every failed BACKUP or RESTORE; the real cause is the error printed just before it. 3117 The log or differential backup cannot be restored because no files are ready to roll forwardA log or differential restore after the database was already recovered (WITH RECOVERY is the default). 3156 File cannot be restored to the location; use WITH MOVERESTORE cannot create a database file at the path stored in the backup; give it a new path with MOVE. 3183 RESTORE detected an error on a page as read from the backup setA page in the backup failed checksum validation during RESTORE: the backup or its source is damaged. 4208 The statement is not allowed while the recovery model is SIMPLEBACKUP LOG on a database in SIMPLE recovery, where log backups do not exist. 4305 The log in this backup set begins at an LSN that is too recent to applyA log backup is missing from the restore sequence; restore the one that contains the LSN named. 1834 The file cannot be overwritten because it is being used by another databaseRESTORE would write a file to a path another attached database uses; restore WITH MOVE to new file names. 3203 Read on the backup device failedThe backup file was opened but could not be read to the end: a truncated copy, a damaged transfer or failing media.

Database State & Recovery 13

945 Database cannot be opened due to inaccessible files or insufficient memory or disk spaceA data or log file could not be opened, so the database is stuck in RECOVERY_PENDING. 926 Database cannot be opened; it has been marked SUSPECT by recoveryRecovery failed and the database was marked SUSPECT; find the cause in the error log and restore. 5120 Unable to open the physical file (operating system error)Attaching or starting a database could not open a file; the OS error says why (missing, access denied, locked). 5123 CREATE FILE encountered an operating system errorA new database file could not be created, usually because the service account cannot write to the folder. 3702 Cannot drop database because it is currently in useDROP DATABASE was refused because a session, often your own, is still using the database. 1813 Could not open new database; CREATE DATABASE is abortedAn attach opened the files but could not start the database; the error printed before 1813 says why. 3414 An error occurred during recovery, preventing the database from restartingRecovery failed at startup and the database was marked SUSPECT; fix the earlier logged error or restore. 5030 The database could not be exclusively locked to perform the operationA collation change or similar ALTER DATABASE needs exclusive access while other sessions are connected. 5173 One or more files do not match the primary file of the databaseAn attach listed a log or data file that belongs to another database or another copy. 9001 The log for database is not availableThe transaction log became unusable (storage, damage, TDE, log full); fix the earlier error and restart the database. 924 Database is already open and can only have one user at a timeThe database is SINGLE_USER and another session already holds its one connection. 942 Database cannot be opened because it is offlineThe database was set OFFLINE; find who did it and bring it back ONLINE. 922 Database is being recovered; waiting until recovery is finishedThe database is still in crash recovery after a restart, restore or ONLINE; wait and check progress.
No errors match. Press Search to search full messages, or browse every error.