![](/img/trans.png)
[英]Field 'user_id' doesn't have a default value, but is set to auto_increment
[英]create table user(“user_id int auto_increment”); not working in derby (embedded database)
我是德比圖書館的新手。 為什么在查詢中使用auto_increment時出現此錯誤?
這是我的java代碼
this.conn.createStatement().execute(create table user("user_id int auto_increment, PRIMARY KEY(user_id))");
我在mysql服務器及其作品中嘗試了此操作,但在derby中卻遇到了此錯誤
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "auto_increment" at line 1
為什么我得到這個錯誤?
Derby沒有使用auto_increment作為關鍵字。 在derby中,您需要使用標識列來實現自動遞增行為
例如
CREATE TABLE students
(
id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
name VARCHAR(24) NOT NULL,
address VARCHAR(1024),
CONSTRAINT primary_key PRIMARY KEY (id)
) ;
上面的語句將創建ID為自動增量列和主鍵的Student表。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.