创建 table 用户("user_id int 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 服务器及其工作中尝试了这个,但在德比中我得到了这个错误
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "auto_increment" at line 1
为什么我会收到这个错误?
Derby 没有 auto_increment 作为关键字。在德比中,您需要使用标识列来实现自动增量行为
例如
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)
) ;
以上语句将创建 Student table,并将 id 作为自动递增列和主键。
希望对您有所帮助
我是德比图书馆的新人。为什么我在查询中使用 auto_increment 时出现此错误?
这是我的 java 代码
this.conn.createStatement().execute(create table user("user_id int auto_increment, PRIMARY KEY(user_id))");
我在 mysql 服务器及其工作中尝试了这个,但在德比中我得到了这个错误
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "auto_increment" at line 1
为什么我会收到这个错误?
Derby 没有 auto_increment 作为关键字。在德比中,您需要使用标识列来实现自动增量行为
例如
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)
) ;
以上语句将创建 Student table,并将 id 作为自动递增列和主键。
希望对您有所帮助