'Can't create new table in Mysql used foreign key [duplicate]
This is what i have used to create new 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)
);
This is the error I'm facing
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
Refer this image :- https://i.stack.imgur.com/uXeoO.png
Solution 1:[1]
AUTO_INCREMENT value is table option, not column option or default value. See CREATE TABLE Statement.
So
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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Akina |
