Nate Nate - 1 month ago 12
MySQL Question

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

Answer

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)
  );
Comments