SQL Error Codes (ANSI)

Search ANSI SQL SQLSTATE codes by value or description.

Reference for ANSI/ISO SQL SQLSTATE codes with class, subclass, condition meaning and common causes — covering success, warning, no-data and exception classes. Runs in your browser.

What is a SQLSTATE?

A SQLSTATE is a 5-character return code defined by the ANSI/ISO SQL standard. The first two characters are the class and the last three the subclass, giving a portable way to identify an error across different database engines.

This is a searchable reference for ANSI/ISO SQL SQLSTATE codes — the portable 5-character return codes that database engines use to report the outcome of a statement. Unlike vendor-specific error numbers, SQLSTATE is part of the SQL standard, so the same class means the same thing across PostgreSQL, MySQL, Oracle, SQL Server and DB2.

How it works

A SQLSTATE is exactly five characters. The first two form the class (a broad category) and the last three the subclass (a refinement, where 000 means “no specific subclass”). Class 00 is success, 01 is a warning, 02 is no-data, and every other class signals an exception. This tool lets you search by a full SQLSTATE, by a two-character class, or by any keyword in the meaning or cause. Each row shows the class, the class meaning, the specific condition and the situation that typically raises it.

Key classes to know

The classes you will hit most often: 22 (data exception — truncation, out-of-range, division by zero), 23 (integrity constraint violation — NOT NULL, UNIQUE, CHECK, FK), 40 (transaction rollback — serialization failure, deadlock) and 42 (syntax error or access rule violation). Connection problems live in class 08, and authorization failures in 28.

Example

When you handle errors portably, match on the class rather than the vendor subclass:

SQLSTATE 23505  ->  class 23 = integrity constraint violation
                    subclass 505 = unique_violation (engine-specific)

Catching class 23 lets your code react to any constraint violation regardless of engine, then drill into the subclass only where you need engine-specific behaviour. Everything here runs in your browser; nothing is uploaded.