What is wrong with the below ENUM (mysql)? - 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) )

Related

MySQL 1064 error on create table

> CREATE TABLE If NOT EXISTS HARDWARE
(
'RECORD_ID' int PRIMARY KEY NOT NULL,
'Asset_Number' int(10) unique not null index,
'Type' char(20) not null,
'Name' varchar(50) not null index,
'Device Description' varchar(50) not null,
'Building' char(40) not null index,
'Date Created' date DEFAULT CURDATE() not null,
'Serial Number' varchar(50) index not null,
'Owner' char(50) index,
'User Created' CHAR ON CREATE USER() INDEX,
'Date Modified' date ON UPDATE CURDATE(),
'Purchase Year' int(4),
'Model' char(50),
'User Modified' CHAR(50),
'PO Number' int(20),
'Location' VARCHAR(50) index,
'OS' VARCHAR(20),
'RAM' int(4),
'Notes' text,
'Verified_By_t' char(50) on update user(),
'Internal IP Address' ON UPDATE USER(),
'Verified_Date_d' date ON UPDATE CURDATE(),
'Ethernet MAC' VARCHAR(20) index,
'Wireless MAC' VARCHAR(20) index,
'Usage' VARCHAR(20),
'Funding Source' VARCHAR(20),
'Lock Combo' int(10),
'ServiceLog::Date Created' VARCHAR(20),
'ServiceLog::Issue' VARCHAR(20),
'Ext. Ethernet Adapter' VARCHAR(20),
'AD' bit,
'Updated' date on update CURDATE(),
'Asset LI Hardware::ID Link' VARCHAR(20),
'Hardware' VARCHAR(20),
'Hardware Asset LI::Description' VARCHAR(20),
'Hardware Asset LI::Location' VARCHAR(20),
'Hardware Asset LI::Type' VARCHAR(20),
'Main Menu::Company' VARCHAR(20)
)
and the error I am getting is
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 ''RECORD_ID' int PRIMARY KEY NOT NULL, 'Asset_Number' int unique not null index, ' at line 3
I have tried varying this with:
CREATE TABLE If NOT EXISTS HARDWARE
(
RECORD_ID int PRIMARY KEY NOT NULL,
Asset_Number int unique not null index,
CREATE TABLE If NOT EXISTS HARDWARE
(
Asset_Number int unique not null index,
and other variations.
This is what I currently have and instead of one error it shows 5 errors.
CREATE TABLE If NOT EXISTS HARDWARE
(
RECORD_ID int PRIMARY KEY NOT NULL,
Asset_Number int unique not null index,
Type char(20) not null,
Name varchar(50) not null index,
Device_Description varchar(50) not null,
Building char(40) not null index,
Date_Created date DEFAULT CURDATE() not null,
Serial_Number varchar(50) index not null,
Owner char(50) index,
User_Created CHAR ON CREATE USER() INDEX,
Date_Modified date ON UPDATE CURDATE(),
Purchase_Year int(4),
Model char(50),
User_Modified CHAR(50),
PO_Number int(20),
Location VARCHAR(50) index,
OS VARCHAR(20),
RAM int(4),
Notes text,
Verified_By_t char(50) on update user(),
Internal_IP_Address ON UPDATE USER(),
Verified_Date_d date ON UPDATE CURDATE(),
Ethernet_MAC VARCHAR(20) index,
Wireless_MAC VARCHAR(20) index,
Usage VARCHAR(20),
Funding_Source VARCHAR(20),
Lock_Combo int(10),
AD bit,
Updated_date on update CURDATE()
)
and the error I see for it:
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 'index, Type char(20) not null, Name varchar(50) not null index, Device_Descripti' at line 4
You have numerous errors in your code. Here are some that I've spotted:
The index should be a separate line, not inline.
MySQL supports ON UPDATE DEFAULT CURRENT_TIMESTAMP . . . for one column and that column should be a datetime.
There is no ON UPDATE USER().
The IP Address does not have a type.
There is no ON CREATE.
(Note: Perhaps the most recent version of MySQL does support some of these options, but they don't look familiar to me.)
I would suggest that you create the table starting with the first column -- say by commenting out all the other columns. Then, add one column at a time and fix the errors as you encounter them.

SQL Enum Error 1064

I am trying to create a table in a MySQL database, I am not sure where I am going wrong with my syntax. In my query it is returning a 1064 error in the line where I use ENUM. Here is part of my query:
CREATE TABLE General
(
pId varchar(30) NOT NULL UNIQUE,
Hometown varchar(30) NOT NULL,
Year char(2) NOT NULL ENUM("FR","SO","JR","SR")
Position varchar(2) NOT NULL ENUM("PG","SG","SF","PF","C"),
Season char(4) NOT NULL DEFAULT 2016,
Date_Of_Birth DATE NOT NULL,
CONSTRAINT PRIMARY KEY (pId));
missing comma , enum don't need type, season is a string '2016' and remove constraint for primary key
CREATE TABLE General
(
pId varchar(30) NOT NULL UNIQUE,
Hometown varchar(30) NOT NULL,
Year ENUM("FR","SO","JR","SR"), <---- here missing commma
Position ENUM("PG","SG","SF","PF","C"),
Season char(4) NOT NULL DEFAULT '2016',
Date_Of_Birth DATE NOT NULL,
PRIMARY KEY (pId)
);

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

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,

Error creating table in MySQL 5.7

Can some one help me in correcting the syntax according to MySQL 5.7?
Table :
CREATE TABLE Employee(
EMPID INT NOT NULL AUTO_INCREMENT,
EMPNAME VARCHAR(20) NOT NULL,
EMPAGE INT NOT NULL,
SALARY BIGINT NOT NULL,
ADDRESS VARCHAR(20) NOT NULL
PRIMARY KEY (ID)
);
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 '(ID)
You forgot comma at the end of this line:
ADDRESS VARCHAR(20) NOT NULL
You dont have a column named ID, you may want EMPID?
Replace
ADDRESS VARCHAR(20) NOT NULL
By
ADDRESS VARCHAR(20) NOT NULL,
There are two problems here:
A primary key clause is it's own clause, and needs to be separated from the previous column definition by a comma.
You don't have an id column - your primary key should (probably) be empid:
CREATE TABLE Employee(
EMPID INT NOT NULL AUTO_INCREMENT,
EMPNAME VARCHAR(20) NOT NULL,
EMPAGE INT NOT NULL,
SALARY BIGINT NOT NULL,
ADDRESS VARCHAR(20) NOT NULL,
PRIMARY KEY (EMPID)
);
I guess this is what you are looking for:
CREATE TABLE Employee(
EMPID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
EMPNAME VARCHAR(20) NOT NULL,
EMPAGE INT NOT NULL,
SALARY BIGINT NOT NULL,
ADDRESS VARCHAR(20) NOT NULL
);

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.