1

I am having trouble writing DDL scripts to create tables. I have written the following code to create the EMPLOYEE and CLIENT table:

CREATE TABLE EMPLOYEE (
    Employee_id INT NOT NULL AUTO_INCREMENT,
    fname VARCHAR (15) NOT NULL,
    minit VARCHAR (1),
    lname VARCHAR (20) NOT NULL,
    address VARCHAR (55),
    start_date date,
    Job_type VARCHAR (20),
    PRIMARY KEY (Employee_id)
);


CREATE TABLE CLIENT (
    Client_id INT NOT NULL Auto_Increment,
    Rest_name VARCHAR (25) NOT NULL,
    Pri_contact_name VARCHAR (25) NOT NULL,
    Pri_phone CHAR (13) NOT NULL,
    Pri_email VARCHAR (35) NOT NULL,
    Cust_addr VARCHAR (50) NOT NULL,
    PRIMARY KEY (Client_id)
);

These tables are created with no issues. However, when I try to create the ORDER table with the following code:

CREATE TABLE ORDER (
    Order_id INT NOT NULL AUTO_INCREMENT,
    Order_Placed CHAR (10) NOT NULL,
    Delivered_on CHAR (10) NOT NULL,
    Total VARCHAR (8) NOT NULL,
    Ship_addr VARCHAR (50) NOT NULL,
    Order_status VARCHAR (35) NOT NULL,
    PRIMARY KEY (Order_id)
);

I received this error:

at line 27: 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 'ORDER ( Order_id int NOT NULL AUTO_INCREMENT,
Order_Placed char(10) NOT NULL' at line 1.

I am not sure why I'm getting this error when I am using the same code from the previous tables that worked.

*I left out FK's out for now just to get the error figured

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
houston
  • 13
  • 6

1 Answers1

3

You'll want to use backticks since ORDER is a reserved keyword:

CREATE TABLE `ORDER` (
    Order_id INT NOT NULL AUTO_INCREMENT,
    Order_Placed CHAR (10) NOT NULL,
    Delivered_on CHAR (10) NOT NULL,
    Total VARCHAR (8) NOT NULL,
    Ship_addr VARCHAR (50) NOT NULL,
    Order_status VARCHAR (35) NOT NULL,
    PRIMARY KEY (Order_id)
);
Daerik
  • 4,167
  • 2
  • 20
  • 33