Informix Error -310: Table table-name already exists in database.
Cause and resolution
Table table-name already exists in database.
This statement tries to create a table with the name that is shown, but one with that name already exists. Only one table with a given name can exist in a single database. (In an ANSI-compliant database, the name of the user that created a table name qualifies it, so one table of a given name per user can exist.)
Check the spelling of the name; if it is as you intended, and you are sure it should not exist, check that you are using the right database. You can review the names of all tables in this database by querying systables as follows:
SELECT tabname FROM systables WHERE tabid > 99
This statement will display only names of permanent tables, not temporary tables. Temporary tables do not appear in systables. If the name does not appear, end your database session and start a new one. Temporary tables will be dropped.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-310 is a straightforward uniqueness restriction: only one table with a given name can exist in a single (non-ANSI) database. ANSI-compliant databases relax this slightly — they allow one table per name per user, qualified by the creator's username — but outside that mode, the name has to be unique across the whole database regardless of who creates it.
- A
CREATE TABLEstatement using a name that already exists in the target database — the direct, most common cause. - Running a setup/migration script more than once without a preceding
DROP TABLE IF EXISTS-equivalent check, so the second run collides with the first. - Wrong database connected — the table doesn't conflict in the database the developer had in mind, but does in whichever database the session is actually connected to.
- In an ANSI-compliant database, a different user's table of the same name already exists, and the current attempt isn't being correctly scoped/qualified as expected.
Solutions / Resolution
- Verify the table name's spelling and confirm it's genuinely intended to be a new, distinct table — per the official guidance.
- Confirm the session is connected to the correct database before running
CREATE TABLE. - Query
systablesto review existing permanent tables in the current database:SELECT tabname, owner FROM systables WHERE tabtype = 'T' AND tabname = 'orders'; - For repeatable setup scripts, drop the existing table first (or check for its existence before creating), rather than assuming a clean database on every run.
- In an ANSI-compliant database, qualify the table name by owner if per-user tables with the same base name are intended.
Examples
Re-running a setup script without a guard
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER
);
-- Running the same script again later:
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER
);
-- -310: orders already exists
Fix — check first, or make the script idempotent:
SELECT tabname FROM systables WHERE tabname = 'orders' AND tabtype = 'T';
-- if found, DROP TABLE orders; before recreating,
-- or skip the CREATE TABLE entirely
Confirming the current database before creating
DATABASE sales;
SELECT tabname FROM systables WHERE tabname = 'orders' AND tabtype = 'T';
-- confirm this really is the intended database before CREATE TABLE
Diagnostic Checks
- Query
systablesfor the table name in question, restricted totabtype = 'T'(permanent tables), to confirm whether it already exists in this database. - Confirm the currently connected database matches the one the script or statement was intended for.
Related Errors / Related Topics
- -296 — "Referenced table table-name not available." Another table-existence-related error, though about a table being missing/unreachable rather than already present.
Query systables first to confirm whether the name is really already taken in this database
before assuming a typo or writing a workaround.