Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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(
id INT PRIMARY KEY,
amount INT NOT NULL,
discount INT NOT NULL,
date_orde' at line 1

What I have tried:

mysql> CREATE TABLE order(
-> id INT PRIMARY KEY,
-> amount INT NOT NULL,
-> discount INT NOT NULL,
-> date_order DATE,
-> order_status VARCHAR(20) NOT NULL);
Posted
Updated 20-Feb-22 21:50pm

You can't call the table "order" - that's a keyword (as in SELECT ... ORDER BY ...)
Change the table name to "Orders" and it should work.
 
Share this answer
 
What is your database name? Normally the following error produce when we used hyphen (−) in the database name, which isn’t acceptable.
You can use the way to create the table in your database:
create table orders(
   id INT NOT NULL,
   amount INT NOT NULL,
   discount INT NOT NULL,
   date_order DATE,
   order_status VARCHAR(20) NOT NULL,
   PRIMARY KEY (id)
);
 
Share this answer
 
v2
The best way to learn how to write this type of SQL is to use a Database Management tool. Create the table in the tool, then select the table and there will be a menu option (usually done by right-clicking on the table name) and it will generate the SQL for you.

For MySql, the management tool is: MySQL Workbench. There are other apps that can do this too...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900