Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get this error "Error code 30000, SQL state 42X01: Syntax error: Encountered "AUTO_INCREMENT" at line 3, column 22." when I create a sql table

Tags:

java

sql

derby

CREATE TABLE Products
(
Item_ID int NOT NULL AUTO_INCREMENT,
item_make varchar(255) NOT NULL,
item_model varchar(255),
brought_in_date varchar(255),
collected_date varchar(255),
whats_wrong varchar(255),
what_was_done varchar(255),
Price varchar(255),
CID varchar(255),
PRIMARY KEY (Item_ID),
FOREIGN KEY (CID) REFERENCES Customers(CID)
)

When I execute this I get this error

  Error code 30000, SQL state 42X01: Syntax error: Encountered "AUTO_INCREMENT" at line 3, column 22.

I am using sql on the java database, derby

Does anyone know what I did wrong.

like image 875
Pirates Avatar asked Oct 26 '25 19:10

Pirates


1 Answers

Instead of AUTO_INCREMENT (which is MySQL dialect), you should use the SQL standard GENERATED ALWAYS AS IDENTITY as supported by Derby:

CREATE TABLE Products
(
Item_ID int GENERATED ALWAYS AS IDENTITY not null primary key,
item_make varchar(255) NOT NULL,
item_model varchar(255),
brought_in_date varchar(255),
collected_date varchar(255),
whats_wrong varchar(255),
what_was_done varchar(255),
Price varchar(255),
CID varchar(255),
FOREIGN KEY (CID) REFERENCES Customers(CID)
)
like image 103
ddb Avatar answered Oct 29 '25 08:10

ddb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!