简体   繁体   中英

unable to create a table in mysql

I have created a database registration in MySQL that already has 2 tables users and employees. I want to create a third table Leave but it is showing error 1064. I have tried everything. Please guide me what is going wrong.

create table leave(
  employeecode int(11) primary key auto_increment,
  description varchar(100) not null,
  fromdate date not null,
  todate date not null,
  status varchar(100) not null
);

Please change table name as per below query it will work.

create table leavetable( 
employeecode int(11) primary key auto_increment, 
description varchar(100) not null, 
fromdate date not null, 
todate date not null, 
status varchar(100) not null 
);

As leave is keyword in mysql used to exit any labeled flow control construct so you can not used keyword as table name.

I tested your code and a found "leave" is a reserved word in sql, so you can change "leave" with "leave_table"

 create table leave_table(
      employeecode int(11) primary key auto_increment,
      description varchar(100) not null,
      fromdate date not null,
      todate date not null,
      status varchar(100) not null
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM