creating a database in MySQL

the below code doesn’t work and when I point the curser on the first line a message says “create” is not valid at this position, expecting EOF’;’
Can someone help please! thank you!

create table users (
id int(11) unsigned auto_increment primary key,
role_id int(11) unsigned,
phone varchar(14),
national_id int(10) not null unique,
email varchar(128) unique,
first_name varchar(32) not null,
sconed name varchar(32) not null,
third_name varchar(32) not null,
last_name varchar(32) not null,
dob date not null,

constraint foreign key(role_id)
references roles(id)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There are two problems:

  • Based on the error, your previous statement is missing ;
  • The SQL query is missing the closing ) or you just forgot it from the paste; something like:
    ) ENGINE=InnoDB AUTO_INCREMENT=1337 DEFAULT CHARSET=utf8mb4;

Method 2

Errors present in the sql statement:

create table users (
id int(11) unsigned auto_increment primary key,
role_id int(11) unsigned,
phone varchar(14),
national_id int(10) not null unique,
email varchar(128) unique,
first_name varchar(32) not null,

sconed name varchar(32) not null,

 second_name varchar(32) not null,     
 third_name varchar(32) not null,

last_name varchar(32) not null,
dob date not null,

constraint foreign key(role_id)
references roles(id)

)

Method 3

create table users (
id int(11) unsigned auto_increment primary key,
role_id int(11),
phone varchar(14),
national_id int(10) not null unique,
email varchar(128) unique,
first_name varchar(32) not null,
sconed_name varchar(32) not null,
third_name varchar(32) not null,
last_name varchar(32) not null,
dob date not null,

constraint foreign key(role_id)
references roles(id));


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x