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)
)
当我执行此操作时,我收到此错误
Error code 30000, SQL state 42X01: Syntax error: Encountered "AUTO_INCREMENT" at line 3, column 22.
我在java数据库上使用sql,derby
有谁知道我做错了什么。
答案 0 :(得分:4)
而不是AUTO_INCREMENT
(这是MySQL方言),您应该使用Derby支持的SQL标准GENERATED ALWAYS AS IDENTITY
:
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)
)
答案 1 :(得分:2)
根据Derby定义表页面,语法如下:
CREATE TABLE PRODUCTS
(
ITEM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)
...
UNIQUE (MAP_ID)
)
此处链接derby docs