Search code examples
mysqlsqlenumscreate-table

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?


Solution

  • 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) )