21

I'm trying to add a gender column to my table with this query:

ALTER TABLE QRCodeUser ADD gender CHAR(1) enum('M','F') NOT NULL;

I get this 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 'enum('M','F') NOT NULL' at line 1

What's my mistake?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
max85
  • 245
  • 1
  • 3
  • 8

2 Answers2

41

Try this (you dont need to specify the size, char(1) ) :

ALTER TABLE QRCodeUser ADD gender  enum('M','F') NOT NULL;
dsharew
  • 10,377
  • 6
  • 49
  • 75
6

Correct usage of syntax:

ALTER TABLE table_name ADD column_name  enum(`field1`,`field2`,...);
Ankush Madankar
  • 3,689
  • 4
  • 40
  • 74
  • enum defines a set of values to be assigned to the column a better example is ALTER TABLE table_name ADD column_name enum(`value1`,`value2`,...,value_n); can't define also CHAR(1) because ENUM os a type mysql internally use int to represents ENUM it uses the ordinal positions of the value in the definition so value1 is eq to 0 value2 is eq to 1 and value_n is eq to n HTH – TexWiller May 09 '19 at 10:11