MySQL ERROR 1064(42000) when using , instead of , - mysql

When am trying to create a table, I meet this error and can't find a solution.
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 'NULL, course_code CHAR(5) NOT NULL, name VARCHAR(150) NOT NULL, PRIMARY KEY(co' at line 1
and the code for creating the table is:
create table courses
(
school_code ENUM('L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M') NOT NULL,
dept_id TINYINT UNSIGNED NOT NULL,
course_code CHAR(5) NOT NULL,
name VARCHAR(150) NOT NULL,
PRIMARY KEY(course_code),
FOREIGN key (school_code, dept_id)
REFERENCES departments (school_code, dept_id)
)
engine = INNODB DEFAULT character SET = utf8 COLLATE = utf8_general_ci;

dept_id TINYINT UNSIGNED NOT NULL,
should be followed by comma. It's not a comma in your code, it just looks like comma.
Below please find same code with a comma:
dept_id TINYINT UNSIGNED NOT NULL,

Related

How do I debug SQL query with the following error message

This is my query.
CREATE TABLE `requirements`
(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`requirement_id` VARCHAR NOT NULL,
`state` VARCHAR NOT NULL,
`city` VARCHAR NOT NULL,
`salary_per_anum` FLOAT NOT NULL,
`is_closed` TINYINT(1) NOT NULL,
`created_updated` DATETIME NOT NULL,
CONSTRAINT `pk_requirements` PRIMARY KEY(`id`)
);
and this is the 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, `state` VARCHAR NOT NULL, `city` VARCHAR NOT NULL, `salary_per_anum` F' at line 1
how can I debug what seems to be the issue?
You need to define a length of the string colum like
`requirement_id` VARCHAR(100)
and the same with column state and city.
But since requirement_id looks like a number id column it must be of the same type as id in table requirements, probably int.
Also your constraint seems to be defined wrong. It should refer to the table requirements.

What is wrong with the below ENUM (mysql)?

I have to create test table for the course and face an issue with ENUM below:
CREATE TABLE IF NOT EXISTS people (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
Lname varchar(20) DEFAULT NULL,
Fname varchar(20) DEFAULT NULL,
Gender ENUM(‘M’, ’F’),
Specialty ENUM(‘1’, ’2’, ’3’, ’4’),
Grade ENUM (‘I’, ’J’, ’M’, ’S’),
Start_date date DEFAULT NULL,
PRIMARY KEY (id)
);
And it does not work - 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 '‘M’, ’F’),
Specialty ENUM(‘1’, ’2’, ’3’, ’4’),
Grade ENU' at line 5"
Whenever I try to create without ENUM fields - everything is fine. If I try to ALTER TABLE with those ENUMs again - it fails.
What is wrong there?
Please try with below query use ' this quote insteated of `
CREATE TABLE IF NOT EXISTS people_tes (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
Lname varchar(20) DEFAULT NULL,
Fname varchar(20) DEFAULT NULL,
Gender ENUM('M', 'F'),
Specialty ENUM('1', '2', '3', '4'),
Grade ENUM ('I', 'J', 'M', 'S'),
Start_date date DEFAULT NULL, PRIMARY KEY (id) )

Im getting an error when creating my database (#1064)

I was trying to create a database using phpmyadmin but I keep on getting error
#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 ') NOT NULL,First Name VARCHAR(30) NOT NULL,Last Name VARCHAR(30) NOT' at line 3
Im using Tomcat version 8.0. Below is the query I am Executing
CREATE TABLE `cs485_lab5`.`Orders` (
`Item Number` VARCHAR(20) NOT NULL,
`Price` DOUBLE(10) NOT NULL,
`First Name` VARCHAR(30) NOT NULL,
`Last Name` VARCHAR(30) NOT NULL,
`Shipping Address` VARCHAR(50) NOT NULL,
`Credit Card` VARCHAR(20) NOT NULL,
`CCN` INT(16) NOT NULL,
PRIMARY KEY (`Credit Card`)
) ENGINE = InnoDB;
Don't specify a length for DOUBLE. Also, if you are designing the table, don't put spaces in the column names. Use names that don't need escaping. Having to use escape characters just clutters up queries unnecessarily.
So:
CREATE TABLE Orders (
`ItemNumber` VARCHAR(20) NOT NULL,
`Price` DOUBLE NOT NULL,
`FirstName` VARCHAR(30) NOT NULL,
`LastName` VARCHAR(30) NOT NULL,
`ShippingAddress` VARCHAR(50) NOT NULL,
`CreditCard` VARCHAR(20) NOT NULL,
`CCN` INT(16) NOT NULL,
PRIMARY KEY (`CreditCard`)
) ENGINE = InnoDB;
Here is a SQL Fiddle.

ERROR 1064 (42000): You have an error in your SQL syntax;

I have a MySQL commands:
CREATE DATABASE IF NOT EXISTS courses;
USE courses
CREATE TABLE IF NOT EXISTS teachers(
id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
name VAR_CHAR(50) NOT NULL,
addr VAR_CHAR(255) NOT NULL,
phone INT NOT NULL,
);
When I run it, I get an 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 'VAR_CHAR(50) NOT NULL, addr VAR_CHAR(255) NOT
NULL, phone INT NOT NULL, )' at line 3
It is varchar and not var_char
CREATE DATABASE IF NOT EXISTS courses;
USE courses;
CREATE TABLE IF NOT EXISTS teachers(
id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
addr VARCHAR(255) NOT NULL,
phone INT NOT NULL
);
You should use a SQL tool to visualize possbile errors like MySQL Workbench.
Try this:
Use back-ticks for NAME
CREATE TABLE `teachers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`addr` varchar(255) NOT NULL,
`phone` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Use varchar instead of VAR_CHAR and omit the comma in the last line i.e.phone INT NOT NULL
);. The last line during creating table is kept "comma free".
Ex:- CREATE TABLE COMPUTER
(
Model varchar(50)
);
Here, since we have only one column ,that's why there is no comma used during entire code.

Mysql syntax error, but where and why? [duplicate]

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 8 years ago.
I just can't understand why I'm having a syntax error on this table creation:
CREATE TABLE IF NOT EXISTS Tasks (
ID INT UNSIGNED NOT NULL auto_increment,
Name VARCHAR(255) DEFAULT '' NOT NULL,
Description TEXT,
Date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Status ENUM('New', 'Assigned', 'In Progress', 'On Hold', 'Done', 'Canceled'),
Priority ENUM('Urgent', 'High', 'Normal', 'Low'),
Creator SMALLINT UNSIGNED DEFAULT '0' NOT NULL,
Assignee SMALLINT UNSIGNED,
Starting DATETIME,
Deadline DATETIME,
Completion DATETIME,
PRIMARY KEY(ID)
) ENGINE = INNODB;
Gives me:
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 DATETIME,
Deadline DATETIME,
Completion DATETIME,
PRIMARY KEY(ID)
) ENG' at line 10
Looks like its giving me trouble with datetime but why? I've used this in another table and it's working.
Thanks.
STARTING is a reserved keyword, It should be escape with backtick,
CREATE TABLE IF NOT EXISTS Tasks
(
ID INT UNSIGNED NOT NULL auto_increment,
Name VARCHAR(255) DEFAULT '' NOT NULL,
Description TEXT,
Date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Status ENUM('New', 'Assigned', 'In Progress', 'On Hold', 'Done', 'Canceled'),
Priority ENUM('Urgent', 'High', 'Normal', 'Low'),
Creator SMALLINT UNSIGNED DEFAULT '0' NOT NULL,
Assignee SMALLINT UNSIGNED,
`Starting` DATETIME,
Deadline DATETIME,
Completion DATETIME,
PRIMARY KEY(ID)
) ENGINE = INNODB;
MySQL Reserved Keyword List
Starting is a reserved keyword. Perhaps you could use a different one.