You are building a database and you have a field that can accept only certain responses. For example, there is a Gender column which accepts only M or F as values.
Gender ENUM('M','F') not null
This means, the columns can take only one of the values explicitly listed in the column specification. Either F or M.
ENUM allows you to specify a restricted set of values the column can hold.
Multiple character values are also allowed.
Gender ENUM('Male','Female') not null
- Create a table:
CREATE TABLE Person ( Name VARCHAR(25) NOT NULL, Gender ENUM('M','F') NOT NULL, Id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY )
Insert a row:
INSERT INTO Person VALUES('John','M',NULL);