SQL Error Codes

SQL Seeker's SQL Error Code Lookup is your go-to reference for decoding common error codes in databases like MySQL and PostgreSQL.

Stuck on an SQL error? Whether you're a beginner facing a syntax error or an intermediate developer troubleshooting a constraint violation, this guide lists error codes, their causes, and practical fixes to get you back on track.

SQL Error Code Reference Table

Error Code

Dialect

Description

Cause

Fix

1064

MySQL

Syntax Error

Invalid SQL syntax, e.g., missing semicolon, incorrect keyword usage, or misplaced clause.

Check query for typos; validate syntax using MySQL docs; ensure proper semicolon; use SHOW WARNINGS; for details.

1054

MySQL

Unknown Column

Column not found in table, incorrect column name, or missing table alias.

Verify column name; check schema with DESCRIBE table_name;; ensure correct aliases in joins.

1146

MySQL

Table Doesn't Exist

Table not found in database, possibly due to typo, wrong database, or dropped table.

Confirm table name; ensure correct database with USE database_name;; list tables with SHOW TABLES;.

1452

MySQL

Foreign Key Constraint Fails

Inserted value violates foreign key; referenced key missing in parent table.

Ensure referenced key exists; check constraints with SHOW CREATE TABLE table_name;; insert valid data.

1062

MySQL

Duplicate Entry

Unique constraint violated, e.g., duplicate primary key or unique index.

Check for existing values with SELECT;; use ON DUPLICATE KEY UPDATE or modify constraints.

1048

MySQL

Column Cannot Be Null

Non-null column received NULL value during insert or update.

Provide a valid value; alter column with ALTER TABLE table_name MODIFY column_name; to allow NULL.

1215

MySQL

Cannot Add Foreign Key Constraint

Mismatch in data types, missing index, or referencing non-unique column.

Match data types; add index with CREATE INDEX;; ensure referenced column is unique or primary key.

1364

MySQL

Field Doesn't Have Default Value

Strict mode enabled; NOT NULL column lacks default value.

Provide value; set default with ALTER TABLE;; disable strict mode with SET sql_mode='';.

2002

MySQL

Can't Connect to MySQL Server

Server down, incorrect host/port, or network issues.

Verify server status; check host/port; ensure permissions with GRANT;; test with mysqladmin ping.

2013

MySQL

Lost Connection During Query

Server timeout, network interruption, or large query execution.

Increase wait_timeout; optimize query; check network stability; reconnect if needed.

42703

PostgreSQL

Undefined Column

Column not found in table or incorrect column name.

Verify column name; check schema with \d table_name in psql; ensure correct case sensitivity.

42P01

PostgreSQL

Undefined Table

Table not found in database or schema; possible typo or wrong schema.

Confirm table and schema; use \dt to list tables; set schema with SET search_path;.

23505

PostgreSQL

Unique Violation

Duplicate value in column with unique constraint.

Check duplicates with SELECT;; use ON CONFLICT; modify constraints if needed.

23503

PostgreSQL

Foreign Key Violation

Inserted value violates foreign key; referenced key missing.

Ensure referenced key exists; check constraints with \d table_name; insert valid data.

42601

PostgreSQL

Syntax Error

Invalid SQL syntax, e.g., missing comma, incorrect keyword.

Validate syntax; use EXPLAIN to identify issues; check PostgreSQL docs; ensure proper punctuation.

22003

PostgreSQL

Numeric Value Out of Range

Value exceeds column’s numeric range or precision.

Adjust value; alter column with ALTER TABLE table_name ALTER COLUMN column_name TYPE;.

22001

PostgreSQL

String Data Right Truncation

String value too long for column’s defined length.

Shorten string; increase length with ALTER TABLE table_name ALTER COLUMN column_name TYPE;.

28P01

PostgreSQL

Invalid Authorization Specification

Incorrect username or password during connection.

Verify credentials; ensure user exists with \du; check pg_hba.conf settings.

53300

PostgreSQL

Too Many Connections

Exceeded maximum number of database connections.

Increase max_connections in postgresql.conf; close idle connections with pg_terminate_backend.

206

SQL Server

Invalid Column Name

Column not found in table or incorrect column name.

Verify column name; check schema with SELECT * FROM INFORMATION_SCHEMA.COLUMNS;.

208

SQL Server

Invalid Object Name

Table or view not found; possible typo or wrong database.

Confirm table name; ensure correct database with USE database_name;; check with SELECT * FROM sys.tables;.

547

SQL Server

Foreign Key Constraint Violation

Inserted value violates foreign key; referenced key missing.

Ensure referenced key exists; check with sp_helpconstraint; insert valid data.

2627

SQL Server

Unique Constraint Violation

Duplicate value in primary key or unique index.

Check duplicates with SELECT;; use MERGE; modify constraints with ALTER TABLE.

8152

SQL Server

String or Binary Data Would Be Truncated

Data exceeds column’s defined length.

Shorten data; increase size with ALTER TABLE table_name ALTER COLUMN column_name;.

1205

SQL Server

Deadlock Detected

Transaction blocked by another, causing deadlock.

Optimize queries; use SET TRANSACTION ISOLATION LEVEL; retry with TRY...CATCH.

18456

SQL Server

Login Failed for User

Incorrect username, password, or insufficient permissions.

Verify credentials; check with SELECT * FROM sys.server_principals;; ensure correct authentication mode.

4060

SQL Server

Cannot Open Database

Database does not exist or user lacks access.

Verify database name; grant access with GRANT CONNECT;; check with SELECT * FROM sys.databases;.

14

SQLite

Unable to Open Database File

Database file not found, locked, or insufficient permissions.

Verify file path; ensure read/write permissions; check if locked by another process.

1

SQLite

Syntax Error

Invalid SQL syntax, e.g., missing semicolon or incorrect keyword.

Check query for typos; validate syntax using SQLite docs; ensure proper punctuation.

19

SQLite

Constraint Violation

Violation of primary key, unique, or foreign key constraint.

Check data for duplicates or invalid references; modify constraints with ALTER TABLE.

5

SQLite

Database is Locked

Another process or transaction is accessing the database.

Close other connections; use PRAGMA busy_timeout;; ensure proper transaction handling.

13

SQLite

Database Disk Image is Malformed

Corrupted database file due to improper shutdown or disk error.

Restore from backup; use .recover command or sqlite3 repair tools.

26

SQLite

File is Not a Database

File format not recognized as a valid SQLite database.

Verify file is a valid SQLite database; recreate database if corrupted; check file extension.

ORA-00904

Oracle

Invalid Identifier

Column, table, or object name not found or incorrectly specified.

Verify names; check schema with SELECT * FROM user_objects;; ensure correct case sensitivity.

ORA-00942

Oracle

Table or View Does Not Exist

Table or view not found in schema or insufficient privileges.

Confirm table name; check with SELECT * FROM user_tables;; grant access with GRANT.

ORA-01400

Oracle

Cannot Insert NULL

Non-null column received NULL value during insert.

Provide a valid value; alter column with ALTER TABLE table_name MODIFY column_name;.

ORA-02291

Oracle

Integrity Constraint Violated

Foreign key violation; referenced key missing in parent table.

Ensure referenced key exists; check constraints with SELECT * FROM user_constraints;.

ORA-00001

Oracle

Unique Constraint Violated

Duplicate value in primary key or unique constraint.

Check duplicates with SELECT;; modify constraints with ALTER TABLE.

ORA-01017

Oracle

Invalid Username/Password

Incorrect credentials or locked account.

Verify credentials; unlock account with ALTER USER user_name ACCOUNT UNLOCK;.