This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed last year.
I am writing an mysql program (using the command line editor):
CREATE TABLE FLIGHTS (
FL_NO VARCHAR(10) NOT NULL PRIMARY KEY,
STARTING VARCHAR(20) NOT NULL,
ENDING VARCHAR(20) NOT NULL,
NO_FLIGTHS INT NOT NULL,
NO_STOPS INT NOT NULL
);
this is somehow gives an error which is surprising. any idea?
Error message:
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 'STARTING VARCHAR(20) NOT NULL,
ENDING VARCHAR(20) NOT NULL,
NO_FLIGHTS INTEGER N' at line 3
STARTING and ENDING are keywords, and MySql does not accept keywords as column names, changing them should help...
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
DROP DATABASE IF EXISTS `company_db`;
CREATE DATABASE `company_db`;
USE `company_db`;
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL;
);
CREATE TABLE roles(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
title VARCHAR (30) NOT NULL,
salary DECIMAL,
department_id INT;
);
CREATE TABLE employee(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
first_name VARCHAR (30) NOT NULL,
last_name VARCHAR (30) NOT NULL,
role_id INT NOT NULL,
manager_id INT;
);
Here's my code above. When I try to run this schema file I get the following 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 '' at line 3
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 ')' at line 1
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 '' at line 5
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 ')' at line 1
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 '' at line 6
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 ')' at line 1
What are they talking about? There isn't even a ')' in line 1. Is there something I'm misunderstanding about this? Thanks in advance!
You have an abundance of ;. This terminates each statement, it should not be present within the create:
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL
);
CREATE TABLE roles(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
title VARCHAR (30) NOT NULL,
salary DECIMAL,
department_id INT
);
CREATE TABLE employee(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
first_name VARCHAR (30) NOT NULL,
last_name VARCHAR (30) NOT NULL,
role_id INT NOT NULL,
manager_id INT
);
In each create statement, you have “;” after the last column… this is interpreted as the end of the SQL statement which is causing a syntax error. Just remove them.
The line numbers are within each statement, and you have extra semicolons. So your:
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL;
);
is two statements. The first:
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL
complains about a syntax error at '' on line 3 (the end, where it is expecting a , or ) and sees neither).
And the second:
);
complains about a syntax error at ')' on line 1 (for obvious reasons).
This question already has answers here:
How can I fix MySQL error #1064?
(3 answers)
Closed 2 years ago.
I have had a problem since working with the new MYSQL version 8.0.18.
Always get the same error message:
SQLSTATE [42000]: Syntax error or access violation: 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 'function) VALUES (?,?,?,?,?)
DROP TABLE IF EXISTS bugtracker1_product_status;
CREATE TABLE bugtracker1_product_status (
statusID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
productID INT(10),
statusTitle VARCHAR(255) NOT NULL DEFAULT '',
type ENUM('bug','suggestion') NOT NULL DEFAULT 'bug',
function ENUM('duplicate','solved','outstanding') NOT NULL DEFAULT 'outstanding',
cssClassName VARCHAR(255) NOT NULL DEFAULT '',
showOrder INT(10) NOT NULL DEFAULT 0,
KEY (productID)
);
Where is the problem?
function ENUM('duplicate','solved','outstanding') NOT NULL DEFAULT 'outstanding',
It works in the MariaDB
Thanks for your help!
Thank you for your support, but unfortunately this does not lead to success. The error remains.
`function` ENUM('duplicate','solved','outstanding') NOT NULL DEFAULT 'outstanding',
Could not prepare statement 'INSERT INTO bugtracker1_product_status (productID, statusTitle, cssClassName, type, function) VALUES (?,?,?,?,?)'
Is there no alternative?
FUNCTION (R); became reserved in 8.0.1
function is a reserved keyword in MySQL. You need to escape it with backticks:
`function` ENUM...
The MySQL docs state that it became reserved in version 8.0.1
This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 3 years ago.
I'm working on a group project and I'm trying to drop my database, but I'm receiving the same error, no matter how I try to manipulate what I wrote. Hopefully someone can help me understand where I went wrong.
For the
type VARCHAR NOT NULL,
description VARCHAR,
image VARCHAR,
I've tried adding in "DEFAULT NULL" and adding in numbers next to VARCHAR. I keep getting the same error message. I left it as what I put above because with my API, I don't want to restrict the amount of characters I'll be receiving when I call on it.
CREATE DATABASE recycleThis_db;
USE recycleThis_db;
CREATE TABLE materials (
id INT(11) NOT NULL AUTO_INCREMENT,
type VARCHAR NOT NULL,
description VARCHAR,
image VARCHAR,
materialID INT(11) NOT NULL,
PRIMARY KEY (id)
);
I keep getting this error message:
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 'NOT NULL,
description VARCHAR,
image VARCHAR,
materialID INT NOT NULL' at line 3
I believe VARCHAR requires a length specifier e.g. VARCHAR(10) or VARCHAR(250)
CREATE TABLE `materials`
( `id` INT(11) NOT NULL AUTO_INCREMENT
, `type` VARCHAR(80) NOT NULL
, `description` VARCHAR(255)
, ...
Reference: https://dev.mysql.com/doc/refman/8.0/en/char.html
excerpt:
The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters.
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 5 years ago.
I can't for the life of me figure out what's wrong with this query:
CREATE TABLE IF NOT EXISTS 'plaintext' (
'id' INT NOT NULL AUTO_INCREMENT,
'name' VARCHAR NOT NULL,
'text' TEXT NOT NULL,
PRIMARY KEY ('id')
)
I am running MySQL version 5.7.14 on WAMP. I am getting this 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 ''id' INT NOT
NULL AUTO_INCREMENT, 'name' VARCHAR NOT NULL, 'text' TEX' at line 2
When trying out the query in phpmyadmin it told me that a symbol name and column definition was expected near 'id' on line 2, and there is an unexpected beginning of a statement near 'id' at line 5.
No clue what this even means to be completely honest with you, I'm quite new to MySQL.
Thanks in advance!
David
I think that the issue is that you are not providing a size for your VARCHAR
CREATE TABLE IF NOT EXISTS 'plaintext' (
'id' INT NOT NULL AUTO_INCREMENT,
'name' VARCHAR(100) NOT NULL,
'text' TEXT NOT NULL,
PRIMARY KEY ('id')
)
This question already has answers here:
Best data type to store money values in MySQL
(13 answers)
Closed 6 years ago.
SQL:
create table rentals
(
RentalID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
CustomerID INT UNSIGNED NOT NULL,
VideoID INT UNSIGNED NOT NULL,
DateOfRental DATE NOT NULL,
RentalCost MONEY NULL
);
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 'MONEY NULL )' at line 7
Instead of MONEY, use DECIMAL(8,2) for example. There is no MONEY type in MySQL.