Oracle 23.26ConstraintsLab-verified · 2026-11-30

ORA-02293: cannot validate - check constraint violated

Rows already in the table fail the CHECK condition you are adding or enabling.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-02293: cannot validate (LAB_A.CK_STOCK_QTY) - check constraint violated

Jump to a cause

  1. 01Adding a CHECK constraint to a table that already has violating rows
  2. 02Re-enabling a constraint that was disabled for a bulk load

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim

ORA-02293 comes from ALTER TABLE, not from INSERT. Oracle checks every existing row when you add a CHECK constraint or enable a disabled one, and stops if any row fails. (A single bad INSERT or UPDATE gives ORA-02290 instead.)

In the lab the cause was a negative stock quantity already in the table, and a lowercase status loaded while the constraint was disabled. In both cases WHERE NOT (condition) found the rows, and the constraint went on after they were fixed.

01Adding a CHECK constraint to a table that already has violating rows

stock had three rows, one of them with qty = -3. ALTER TABLE stock ADD CONSTRAINT ck_stock_qty CHECK (qty >= 0); failed with cannot validate (LAB_A.CK_STOCK_QTY) - check constraint violated. The new rule is checked against old data too.

After setting the negative quantity to 0, the same ALTER TABLE succeeded and USER_CONSTRAINTS showed ENABLED / VALIDATED.

Setup
Setuprun as lab_a
CREATE TABLE stock (item_id NUMBER PRIMARY KEY, qty NUMBER);
INSERT INTO stock VALUES (1, 10);
INSERT INTO stock VALUES (2, -3);
INSERT INTO stock VALUES (3, 5);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
ALTER TABLE stock ADD CONSTRAINT ck_stock_qty CHECK (qty >= 0);
✕ ERROR
ALTER TABLE stock ADD CONSTRAINT ck_stock_qty CHECK (qty >= 0)
                                 *
ERROR at line 1:
ORA-02293: cannot validate (LAB_A.CK_STOCK_QTY) - check constraint violated
Help: https://docs.oracle.com/error-help/db/ora-02293/
Check the causerun as lab_a
SELECT item_id, qty FROM stock WHERE NOT (qty >= 0);
OUTPUT
   ITEM_ID        QTY
---------- ----------
         2         -3

1 row selected.

Wrap the constraint condition in NOT (...). The query returned item 2 with qty = -3, the only row blocking the constraint.

Fixrun as lab_a
UPDATE stock SET qty = 0 WHERE qty < 0;
COMMIT;
OUTPUT
1 row updated.


Commit complete.

Decide what the bad rows should be (here 0), fix them, then add the constraint again.

After the fixrun as lab_a
ALTER TABLE stock ADD CONSTRAINT ck_stock_qty CHECK (qty >= 0);
COLUMN constraint_name FORMAT A14
COLUMN search_condition FORMAT A12
SELECT constraint_name, search_condition, status, validated FROM user_constraints WHERE table_name = 'STOCK' AND constraint_type = 'C';
✓ SUCCESS
Table altered.


CONSTRAINT_NAM SEARCH_CONDI STATUS                         VALIDATED
-------------- ------------ ------------------------------ -------------
CK_STOCK_QTY   qty >= 0     ENABLED                        VALIDATED

1 row selected.

02Re-enabling a constraint that was disabled for a bulk load

ck_orders_status allows only 'NEW', 'PAID', 'SHIPPED'. It was disabled, and during that time a row with 'paid' (lowercase) was inserted. ALTER TABLE orders ENABLE CONSTRAINT ck_orders_status; then failed with ORA-02293.

After UPDATE ... SET status = UPPER(status) on the bad row, the enable succeeded and all three rows were NEW, PAID, SHIPPED.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, status VARCHAR2(10), CONSTRAINT ck_orders_status CHECK (status IN ('NEW', 'PAID', 'SHIPPED')));
INSERT INTO orders VALUES (1, 'NEW');
COMMIT;
ALTER TABLE orders DISABLE CONSTRAINT ck_orders_status;
INSERT INTO orders VALUES (2, 'paid');
INSERT INTO orders VALUES (3, 'SHIPPED');
COMMIT;
OUTPUT
Table created.


1 row created.


Commit complete.


Table altered.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
ALTER TABLE orders ENABLE CONSTRAINT ck_orders_status;
✕ ERROR
ALTER TABLE orders ENABLE CONSTRAINT ck_orders_status
                                     *
ERROR at line 1:
ORA-02293: cannot validate (LAB_A.CK_ORDERS_STATUS) - check constraint violated
Help: https://docs.oracle.com/error-help/db/ora-02293/
Check the causerun as lab_a
SELECT order_id, status FROM orders WHERE status NOT IN ('NEW', 'PAID', 'SHIPPED');
OUTPUT
  ORDER_ID STATUS
---------- ------------------------------
         2 paid

1 row selected.

The NOT IN query returned order 2 with paid. String comparison is case-sensitive, so it does not match 'PAID'.

Fixrun as lab_a
UPDATE orders SET status = UPPER(status) WHERE status NOT IN ('NEW', 'PAID', 'SHIPPED');
COMMIT;
OUTPUT
1 row updated.


Commit complete.

Before enabling, clean up the rows loaded while the constraint was off.

After the fixrun as lab_a
ALTER TABLE orders ENABLE CONSTRAINT ck_orders_status;
SELECT order_id, status FROM orders ORDER BY order_id;
✓ SUCCESS
Table altered.


  ORDER_ID STATUS
---------- ------------------------------
         1 NEW
         2 PAID
         3 SHIPPED

3 rows selected.

FAQ

What is the difference between ORA-02293 and ORA-02290?

ORA-02290 is raised when one INSERT or UPDATE breaks an existing CHECK constraint. ORA-02293 is raised by ALTER TABLE ... ADD CONSTRAINT or ENABLE CONSTRAINT when rows already in the table break the condition.

How do I find the rows that violate the check constraint?

Query the table with the condition negated, e.g. SELECT item_id, qty FROM stock WHERE NOT (qty >= 0);. In the lab it returned exactly the one row that blocked the constraint.

Why does ENABLE CONSTRAINT fail when the constraint already exists?

While it was disabled, rows that break the rule could be inserted. Enabling checks all rows again. In the lab a lowercase 'paid' inserted during that time caused ORA-02293.

How do I confirm the constraint is active after the fix?

Check USER_CONSTRAINTS: after the fix the lab showed STATUS = ENABLED and VALIDATED = VALIDATED for CK_STOCK_QTY.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0