无法在 Mysql 使用的外键中创建新的 table

Can't create new table in Mysql used foreign key

这是我用来创建新的 table

CREATE TABLE history(  
search_id int auto_increment=1000 primary key,  
f_name varchar(100) not null,  
f_lo varchar(300) not null,  
u_id varchar(50) not null unique,  
foreign key(u_id) references userinfo(user_id)  
);  

这是我遇到的错误

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=1000 primary key, f_name varchar(100) not null, f_lo varchar(300) not null, u_i' at line 2

参考这张图片:- https://i.stack.imgur.com/uXeoO.png

CREATE TABLE history(
search_id int auto_increment primary key,
f_name varchar(100) not null,
f_lo varchar(300) not null,
u_id varchar(50) not null unique,
foreign key(u_id) references userinfo(user_id)
);

尽量不要初始化自增

创建以上 table 后,您可以通过以下方式更改它:

ALTER TABLE history AUTO_INCREMENT = 1000;

link to refer

AUTO_INCREMENT 值是 table 选项,而不是列选项或默认值。参见 CREATE TABLE Statement

所以

CREATE TABLE history(
    search_id int auto_increment primary key,
    f_name varchar(100) not null,
    f_lo varchar(300) not null,
    u_id varchar(50) not null unique,
    foreign key(u_id) references userinfo(user_id)
) AUTO_INCREMENT = 1000;