Search code examples
javasqlnetbeansderbyjavadb

Netbeans issues Error code -1, SQL state 42Z93 when trying to execute a CREATE TABLE sql command


This is what I try to execute:

CREATE TABLE "order" (
    "o_id" INTEGER not null primary key,
    "c_id" INTEGER,
    PRIMARY KEY (o_id),
    FOREIGN KEY (c_id) REFERENCES customer(c_id)
);

Get this error when I execute the above SQL command:

Error code -1, SQL state 42Z93: Constraints 'SQL120326130633321' and 'SQL120326130633320' have the same set of columns, which is not allowed.

Before the above SQL command I executed this:

CREATE TABLE "customer" (
    "c_id" INTEGER not null primary key,
    "c_first" VARCHAR(30),
    "c_last" VARCHAR(30)
);

EDIT(solution):

I think I fixed it.

First, I had to remove the PRIMARY KEY(o_id) since it basically repeated what I have typed on line 2 of SQL command o_id INTEGER not null primary key so it complained I tried to create primary key for the same column twice.

Second, after that was fixed another error surfaced telling me that CUSTOMER table couldn't be found. Perhaps the problem was that I used the commas("...") around the table name 'customer' when CREATE TABLE was trying to execute.

I deleted 'customer' table and recreated it without using any quotations in the SQL command.

Afterwards I executed the 'CREATE TABLE' for 'orders' and it worked.

Strange difference is that when I used the quotations around the customer table name in SQL, at first, its name appeared all lower case in the Databases Explorer of Netbeans. But when I omitted the quotes the table names became all uppercase - even thier column names.


Solution

  • You are adding the primary key constraint twice. You only need it once, in one place or the other depending on DB vendor.