Hardik D. Bhumkar Hardik D. Bhumkar - 1 month ago 6
MySQL Question

The table customer is successfully created with a primary key cust_id,Why is this still showing errors?

mysql> create table order(order_no int primary key,cust_no int,foreign key(cust_no) references customer(cust_no),order_date date,ship_date date,tocity varchar(20),tostate varchar(20),zip int);



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 'order(order_no int primary key,cust_no int,tocity
varchar(20),tostate varchar(20' at line 1

Answer

NOTE: since order is a keyword, you can only access it as:

   select * from `order`   

 create table `order`(order_no int,cust_no int,foreign key(cust_no) references customer(cust_no),order_date date,ship_date date,tocity varchar(20),tostate varchar(20),zip int, primary key (order_no));