Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding new enum column to an existing table

Tags:

enums

mysql

alter

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?

like image 522
max85 Avatar asked May 09 '15 12:05

max85


People also ask

How do you add a new column to an existing column in MySQL?

The syntax to add a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition [ FIRST | AFTER column_name ];

How do I create an enum in SQL?

In MySQL one can create an enum as such: USE WorldofWarcraft; CREATE TABLE [users] ( ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY, username varchar(255), password varchar(255), mail varchar (255), rank ENUM ('Fresh meat', 'Intern','Janitor','Lieutenant','Supreme being')DEFAULT 'Fresh meat', );

How do I add multiple columns to an existing table in MySQL?

In MySQL, to add a new column to an existing table, the ALTER TABLE syntax would look like this: ALTER TABLE table_name ADD COLUMN column_name column_definition; Let's try adding multiple columns in one command.


1 Answers

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

ALTER TABLE QRCodeUser ADD gender  enum('M','F') NOT NULL;
like image 135
dsharew Avatar answered Sep 17 '22 18:09

dsharew