mySQL - create table error 1064(42000): syntax error - mysql

I'm trying to create the table below but I get an error. I double checked and the data types are valid, and a table with this name doesn't currently exist in the database. I even closed and re-opened my terminal in case this was a glitch. But still no luck. Any idea what's wrong here?
create table order (order_no int, purch_amt decimal(6,2), order_date date, customer_id int, salesman_id int);
Error message I get:
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, purch_amt decimal(6,2), order_date date, customer_id int, s' at line 1

order is SQL keyword. I would suggest calling the table orders. I would suggest:
create table orders (
order_no int,
purch_amt decimal(6,2),
order_date date,
customer_id int,
salesperson_id int
);

Related

ERROR 1064 (42000) in creating table using MySQL 8.0 command line

I'm trying to create a table Order but somehow I am encountering the error code below:
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(
OrderId int,
CustId int,
OrderDate datetime,
RequiredDate datetime,
Shipp' at line 1
I use the following code to create my table:
create table Order(
-> OrderId int,
-> CustId int,
-> OrderDate datetime,
-> RequiredDate datetime,
-> ShippedDate datetime,
-> Status varchar(12),
-> Comments varchar(255)
-> );
We don't need to set primary key or foreign key but I don't know what went wrong with my code. Please advice thanks!
Thanks #jarlh I didn't know it was a reserve word. I just started SQL.

Error to create a brand new table

I tried to create a brand new table with codes:
MySQL [distributor]> create table order
-> (
-> order_num integer not null,
-> order_date datetime not null,
-> cust_id chat(10) not null
-> );
It generates errors:
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_num integer not null,
order_date datetime not null,
cust_id chat(' at line 1
I have checked multiple times to ensure there no problems in my codes since SQL is case-insensitive.
What's the bug with my code?
There are two issues with your query: Firstly, order is a MySQL reserved word. Secondly, you have chat which should be char. Try this instead (renaming table to orders):
CREATE TABLE orders
(
order_num integer not null,
order_date datetime not null,
cust_id char(10)
);
order it's a reserved word and put char instead of chat. You can name the table orders

MySQL error 1064 table creation

This seems a fairly trivial problem but I am having no luck in running the following query:
create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR(20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );
When I run this I get the following error message:
Error Code: 1064. 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 '(20), retweet_count INT, favourite_count INT,
tweet_followers_count ' at line 3
When I hover over the error tag on line 3 it says:
Syntax error : unexpected '(' (opening parenthesis)
I'm sure this is a simple fix, any help would be great!
Turned out to be an error with mySQL Workbench
create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR (20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );
Man this code is running perfectly.
go to this link and check it your self
http://rextester.com/l/mysql_online_compiler

MySQL CREATE TABLE 'You have an error in your SQL syntax' error [duplicate]

This question already has answers here:
Error creating table: You have an error in your SQL syntax near 'order( order_id INT UNSIGNED NOT NULL AUTO_INCREMENT, user_id ' at line 1 [duplicate]
(2 answers)
Closed 5 years ago.
I am pulling my hair out over this. I have connected to a MySQL server and am trying to create a table on it:
CREATE TABLE order (
order_id INT,
order_is_overnight BIT,
order_quantity INT,
order_amount DOUBLE,
order_timestamp DATETIME
);
When I run this I get:
Error: 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,
order_is_overnight BIT,
order_quantity INT,
order_amou' at line 1
SQLState: 42000
ErrorCode: 1064
This is the world's vaguest error message, akin to a Java exception that says "Whoops, something went wrong somewhere in your code!"
Any ideas where I'm going awry?! I have checked, and rechecked, and rechecked and this seems to be a perfectly valid/legal CREATE TABLE statement (don't worry about performance, indexes, keys, etc.; this is just a dummy/test table).
order is an reserved word, you must enclose it name in back quotes
CREATE TABLE `order` (
order_id INT,
order_is_overnight BIT,
order_quantity INT,
order_amount DOUBLE,
order_timestamp DATETIME
);

Create MySQL Database with Xampp

I have the following query for creating a table in my database but I am getting an error:
CREATE TABLE student (
accountNumber INT NOT NULL PRIMARY KEY,
firstName CHAR(20),
lastName CHAR(20),
courseID VARCHAR(6),
grade DOUBLE(3)
)
The error I am getting is:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '))' at line 1
You dont need NOT NULL if declaring a Primary Key...because that key always needs to be available