Informix Error -540
-540 Write failed on constraints.
An error occurred while defining a constraint. Possibly you have defined a constraint whose name duplicates the name of another constraint, table, or index. If this is the case, repeat the statement, specifying a unique name. Otherwise, check the accompanying ISAM error code for more information.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-540 fires while the server is writing a new constraint's catalog entries, most often because the constraint's name collides with an existing name in the same namespace.
- A constraint name duplicating another constraint, table, or index name — per the official guidance, the most likely cause, since Informix requires these names to be unique within their scope.
- An underlying ISAM-level failure during the catalog write — per the official guidance, check the accompanying ISAM error code when a naming collision isn't the explanation.
- A system-generated constraint name colliding with a name chosen explicitly elsewhere, since unnamed constraints get an automatically generated name that could theoretically collide with one a later statement names explicitly.
Solutions / Resolution
- Check whether the constraint's name duplicates an existing constraint, table, or index
name, per the official guidance — query
sysconstraints/systables/sysindexesfor the name before retrying. - Repeat the statement with a unique name, per the official guidance, once a collision is confirmed.
- If no naming collision is found, check the accompanying ISAM error code, per the official guidance, for the actual underlying cause.
Examples
A duplicate constraint name
ALTER TABLE orders ADD CONSTRAINT
CHECK (status IN ('pending','shipped')) CONSTRAINT ck_status;
-- ck_status already exists as a constraint on a different table
-- -540: Write failed on constraints.
Checking for the collision
SELECT constrname, tabid FROM sysconstraints WHERE constrname = 'ck_status';
Corrected with a unique name
ALTER TABLE orders ADD CONSTRAINT
CHECK (status IN ('pending','shipped')) CONSTRAINT ck_orders_status;
Diagnostic Checks
- Query
sysconstraints,systables, andsysindexesfor the chosen constraint name to confirm whether it collides with an existing object before assuming an ISAM-level cause. - Check the accompanying ISAM error code if no naming collision is found.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -540 in this set yet.
Usually a name collision — check sysconstraints/systables/sysindexes for the chosen name
first, then fall back to the accompanying ISAM error code.