-1

the query is

CREATE TABLE order(
    order_id int primary key,
    customer_name varchar(30) not null,
    product_name varchar(20) not null,
    date_ordered date,
    quantity int,
    unit_price float,
    phone_no varchar(20)
);

the error is :

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_id int primary key, customer_name varchar(30) not null, ' at line 1

i am using MySQL verson 8.0.32

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • 1
    `ORDER` is a [reserved keyword](https://dev.mysql.com/doc/refman/8.0/en/keywords.html) in mysql. Name your table differently .. I'd suggest `orders` because in the end of the day, your table will be a collection of multiple `orders` – derpirscher Jan 21 '23 at 08:38
  • 1
    Or enclose your table name in backticks, to make it an identifier (but still you shouldn't use keywords as identifiers). `CREATE TABLE \`order\` ( ....) ` – derpirscher Jan 21 '23 at 08:48

3 Answers3

1

Because order is part of the SQL syntax (to sort queried records using ORDER BY) it wont work.

You have to rename your table to something different like for example orders then it will work:

CREATE TABLE orders (
   order_id int primary key,
   customer_name varchar(30) not null,
   product_name varchar(20) not null,
   date_ordered date,
   quantity int,
   unit_price float,
   phone_no varchar(20)
);
hc_dev
  • 8,389
  • 1
  • 26
  • 38
0

ORDER is part os mysql syntax just use another name for your table like orders:

CREATE TABLE orders (
order_id int primary key,
customer_name varchar(30) not null,
product_name varchar(20) not null,
date_ordered date,
quantity int,
unit_price float,
phone_no varchar(20)
);
Avad
  • 197
  • 1
  • 8
0

order is a keyword you cannot use it.To know the list of other keywords check the below link https://dev.mysql.com/doc/refman/8.0/en/keywords.html

Fedor
  • 17,146
  • 13
  • 40
  • 131