So I'm getting an error when trying to run this script in MariaDB that reads as follows: "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
CREATE TABLE customers (
customer_id int NOT NULL,
customer_f
at line 1
The weird thing is that MariaDB seems to be reading the first line of the command and then a little bit of the next line as 1 line. The whole script is below: if anyone could help I would greatly appreciate it.
DROP TABLE customers;
DROP TABLE orders;
DROP TABLE products;
DROP TABLE orderitem;
CREATE TABLE customers (
customer_id INT NOT NULL AUTO_INCREMENT,
customer_firstname VARCHAR(20) NOT NULL,
customer_lastname VARCHAR(40) NOT NULL,
customer_phone CHAR(10) NOT NULL,
customer_email VARCHAR(60) NOT NULL,
customer_address VARCHAR(40) NOT NULL,
customer_city VARCHAR(40) NOT NULL,
customer_state CHAR(2) NOT NULL,
customer_zip VARCHAR(10) NOT NULL,
customer_aptnum VARCHAR(5) NOT NULL,
customer_pass CHAR(40) NOT NULL,
customer_type VARCHAR(10) NOT NULL,
PRIMARY KEY (customer_id),
INDEX customer_fullname (customer_firstname, customer_lastname),
UNIQUE (customer_email)
);
CREATE TABLE orders (
order_id INT NOT NULL AUTO_INCREMENT,
order_datetime DATETIME NOT NULL,
order_trackingnumber VARCHAR(20) NOT NULL,
order_shipdate DATETIME NOT NULL,
order_shipmethod VARCHAR(10) NOT NULL,
order_shipcarrier VARCHAR(10) NOT NULL,
order_totalprice DECIMAL,
customer_id INT NOT NULL,
PRIMARY KEY (order_id),
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
UNIQUE (order_trackingnumber)
);
CREATE TABLE products (
product_id VARCHAR(30) NOT NULL AUTO_INCREMENT,
product_beginningstockdate DATETIME NOT NULL,
product_endstockdate DATETIME,
product_category VARCHAR(15) NOT NULL,
product_name VARCHAR(60) NOT NULL,
product_availablequantity SMALLINT NOT NULL,
product_totalquantity SMALLINT NOT NULL,
product_price DECIMAL NOT NULL,
product_taxable DECIMAL NOT NULL,
product_itemstatus VARCHAR(15) NOT NULL,
product_discountpercent DECIMAL,
product_soldinstore char(3),
product_soldonwebsite char(3),
PRIMARY KEY (product_id),
UNIQUE (product_name)
);
/*INSERT INTO products (product_description, product_beginningstockdate, product_endstockdate, product_category, product_name, product_availablequantity, product_totalquantity, product_price, product_taxable, product_itemstatus, product_discountpercent, product_soldinstore, product_soldonwebsite)
VALUES
(...),
(...),
........ */
CREATE TABLE orderitem (
orderitem_id INT NOT NULL AUTO_INCREMENT,
order_id INT NOT NULL,
product_id VARCHAR(30) NOT NULL,
orderitem_priceperunit DECIMAL NOT NULL,
orderitem_quantityordered TINYINT NOT NULL,
PRIMARY KEY (orderitem_id),
FOREIGN KEY (order_id) REFERENCES orders(order_id),
FOREIGN KEY (product_id) REFERENCES orders(product_id)
);
Copy&pasting your code into NotePad++ and then viewing it in the hex editor shows that you have 80 8b 0a in each of those empty lines between the statements.
That byte sequence is the UTF-8 encoded form of the zero-width space character.
See to it that you remove those – then it should work.
(If you’re using NotePad++ and the hex editor plugin, then in hex view you can simply replace e2 80 8b with an empty string. Otherwise, in any other text editor, going to the end of the previous line, selecting everything from there over the empty line until the beginning of the next line, and then replacing the selection by pressing enter should also work.)
I had a similar frustration and discovered I needed to change my delimiter around my procedure. Perhaps it'll work here too.
DELIMITER //
CREATE PROCEDURE
....
BEGIN
END //
DELIMITER ;
Related
Here is my failing MySQL code:
CREATE TABLE product (
id int NOT NULL AUTO_INCREMENT,
'item-name' VARCHAR(255) NOT NULL,
'item-description' TEXT,
'listing-id' VARCHAR(50),
PRIMARY KEY (id)
)
The error is:
Error creating table: 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
'item-name' VARCHAR(255) NOT NULL, 'item-description' TEXT, 'listing-id'' at line 3
The documentation says to use quotes... What is wrong?
Use ` instead of ':
CREATE TABLE product (
id int NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
You should use the back-quote (`) to quote column names, not the single-quote ('). Look above the tilde key (~).
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
Why do you use quotes? You should use backticks. Try this:
CREATE TABLE product (
id int NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
Please, use normal character in table definition. You can use underscore "_" instead "-".
When you'll query your db, you must always use quote. Impossible for me! :)
If you want follow this road, use the quote
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
maybe it is coming late. but this worked for me.
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
[item-name] VARCHAR(255) NOT NULL,
[item-description] TEXT,
[listing-id] VARCHAR(50),
PRIMARY KEY (id)
)
I'm trying to create a database in Ubuntu using MySQL in the command line, I need to create a table with the following data:
CREATE TABLE Vehicles (
Vehicle_ID int NOT NULL,
Vehicle_Type VARCHAR(255) NOT NULL,
Model_name VARCHAR(255) NOT NULL,
Engine_Size float(1,1) NOT NULL,
Condition VARCHAR(255) NOT NULL,
Price float(9,2) NOT NULL,
PRIMARY KEY (Vehicle_ID)
);
It just returns an error that says "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 'Condition varchar(255) NOT NULL,
Price float(9,2) NOT NULL,
PRIMARY KEY (Vehicle' at line 6"
What is wrong with my code? The "Price" and "Engine_Size" columns need to only be a float/decimal values so they can't be varchar because I want to only be able to insert numbers.
This works:
CREATE TABLE Vehicles (
Vehicle_ID int NOT NULL,
Vehicle_Type VARCHAR(255) NOT NULL,
Model_name VARCHAR(255) NOT NULL,
Engine_Size int NOT NULL,
Vehicle_Condition VARCHAR(255) NOT NULL,
Price numeric(9,2) NOT NULL,
PRIMARY KEY (Vehicle_ID)
);
Notes:
For Price you seem to want numeric, not float, because you are specifying the precision and scale.
For Engine_Size, I have no idea what float(1, 1) is supposed to mean. I am guessing that int is an appropriate type.
Condition is a reserved word in MySQL, so I changed the name of the column.
The only apparent problem in your code is the use of 'condition' as a column name as condition is a reserved word in MySQL.
You can fix it in 2 ways:
Don't use 'condition' as a column name:
CREATE TABLE Vehicles (
Vehicle_ID int NOT NULL,
Vehicle_Type VARCHAR(255) NOT NULL,
Model_name VARCHAR(255) NOT NULL,
Engine_Size float(1,1) NOT NULL,
V_Condition VARCHAR(255) NOT NULL, //Just an example feel free to use any another name
Price float(9,2) NOT NULL,
PRIMARY KEY (Vehicle_ID)
);
Put 'condition' inside backticks (``)
CREATE TABLE Vehicles (
Vehicle_ID int NOT NULL,
Vehicle_Type VARCHAR(255) NOT NULL,
Model_name VARCHAR(255) NOT NULL,
Engine_Size float(1,1) NOT NULL,
`Condition` VARCHAR(255) NOT NULL,
Price float(9,2) NOT NULL,
PRIMARY KEY (Vehicle_ID)
);
Hope this helps
I am new to MySQL and am uploading a database for the first time. I am not uploading the data, just the columns for now. The issue is that I get an error for every line of code provided:
#1064 - You have an error in your SQL syntax;
I can understand if I was getting the message for just one or two lines of the code, but I am beginning to think I misformatted all the database file since I'm getting that error message for every line.
I previously changed the primary/foreign keys
CONSTRAINT `PurchasePK` PRIMARY KEY (`P_ORDERNO`)
CONSTRAINT `PurchaseFK` FOREIGN KEY (`SUPPLY_CODE`)
to: P_ORDERNO int(5) NOT NULL auto_increment PRIMARY KEY,
And still get errors.
I would appreciate if someone took a look at the contents of the .sql file below and let me know if there is something I am missing that is giving me consistent errors.
-- Table structure for table `Purchase`
CREATE TABLE IF NOT EXISTS `Purchase` (
`P_ORDERNO` int(5) NOT NULL auto_increment PRIMARY KEY,
`SUPPLY_CODE` int(5) NOT NULL auto_increment FOREIGN KEY,
`P_ORDER_DATE` timestamp NOT NULL,
`P_ORDER_AMT` int(5) NOT NULL,
`SUPPLY_DESC` varchar(50) NULL,
`SUPPLY QTY` int(5) NOT NULL,
);
ENGINE = InnoDB;
-- Table structure for table `Vendor`
CREATE TABLE IF NOT EXISTS `Vendor` (
`VENDORNO` int(5) NOT NULL auto_increment PRIMARY KEY,
`VENDOR_NAME` varchar(50) NULL,
`VENDOR_STREET` varchar(50) NULL,
`VENDOR_CITY` varchar(50) NULL,
`VENDOR_STATE` varchar(2) NULL,
`VENDOR_ZIP` varchar(3) NULL,
`VENDOR_AREA_CODE` varchar(5) NULL,
`VENDOR_PHONE` varchar(10) NULL,
);
ENGINE = InnoDB;
-- Table structure for table `Supply`
CREATE TABLE IF NOT EXISTS `Supply` (
`SUPPLY_CODE` int(5) NOT NULL auto_increment PRIMARY KEY,
`SUPPLY_DESC` varchar(50) NULL,
`SUPPLY QTY` int(5) NOT NULL,
);
ENGINE = InnoDB;
You have trailing commas
`SUPPLY QTY` int(5) NOT NULL,
^---here
);
in each of the table definitions. That makes the DB server expect another field definition, but instead it runs into );
Here is my failing MySQL code:
CREATE TABLE product (
id int NOT NULL AUTO_INCREMENT,
'item-name' VARCHAR(255) NOT NULL,
'item-description' TEXT,
'listing-id' VARCHAR(50),
PRIMARY KEY (id)
)
The error is:
Error creating table: 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
'item-name' VARCHAR(255) NOT NULL, 'item-description' TEXT, 'listing-id'' at line 3
The documentation says to use quotes... What is wrong?
Use ` instead of ':
CREATE TABLE product (
id int NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
You should use the back-quote (`) to quote column names, not the single-quote ('). Look above the tilde key (~).
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
Why do you use quotes? You should use backticks. Try this:
CREATE TABLE product (
id int NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
Please, use normal character in table definition. You can use underscore "_" instead "-".
When you'll query your db, you must always use quote. Impossible for me! :)
If you want follow this road, use the quote
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
`item-name` VARCHAR(255) NOT NULL,
`item-description` TEXT,
`listing-id` VARCHAR(50),
PRIMARY KEY (id)
)
maybe it is coming late. but this worked for me.
CREATE TABLE product (
id INT NOT NULL AUTO_INCREMENT,
[item-name] VARCHAR(255) NOT NULL,
[item-description] TEXT,
[listing-id] VARCHAR(50),
PRIMARY KEY (id)
)
CREATE TABLE Customer(
custID INT NOT NULL AUTO_INCREMENT,
custName VARCHAR(255) NOT NULL,
custAddress VARCHAR(255) NOT NULL,
CONSTRAINT pk_Customer PRIMARY KEY (custID)
),
I have this as part of a database I'm setting up, yet whenever I try to run the .sql file that this is included in, I get the following error:
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 '
CREATE TABLE Customer(
custID INT NOT NULL AUTO_INCREMENT,
custName VARCHAR(' at line 8
Any ideas what's wrong? Thanks.
Remove the , from the end CREATE TABLE statement
CREATE TABLE Customer(
custID INT NOT NULL AUTO_INCREMENT,
custName VARCHAR(255) NOT NULL,
custAddress VARCHAR(255) NOT NULL,
CONSTRAINT pk_Customer PRIMARY KEY (custID)
)
Or use semicolon instead comma:
CREATE TABLE Customer(
custID INT NOT NULL AUTO_INCREMENT,
custName VARCHAR(255) NOT NULL,
custAddress VARCHAR(255) NOT NULL,
CONSTRAINT pk_Customer PRIMARY KEY (custID)
);
You have comma at the end if you remove that it is working fin for me.
CREATE TABLE Customer(
custID INT NOT NULL AUTO_INCREMENT,
custName VARCHAR(255) NOT NULL,
custAddress VARCHAR(255) NOT NULL,
CONSTRAINT pk_Customer PRIMARY KEY (custID)
)
We don't use "," at the end to separate two sql queries, you have to use ";" and if you are running a single query then you don't need.
CREATE TABLE Customer(
custID INT NOT NULL AUTO_INCREMENT,
custName VARCHAR(255) NOT NULL,
custAddress VARCHAR(255) NOT NULL,
CONSTRAINT pk_Customer PRIMARY KEY (custID)
)