user1479431 user1479431 - 4 months ago 6x
MySQL Question

Basic MySQL query

In MySQL, I need to create a new table called users with the following fields:

id – integer type (primary key)
first_name – varchar type
username – varchar type
password – char type with length 40 (this is the length of a sha1 hash)
type – varchar type (‘admin’ or ‘author’)

Everything looks straight forward except

type – varchar type (‘admin’ or ‘author’) .

How do I do this?


You want to use MySQL's ENUM datatype:

An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time.

Therefore, in your case:

`Type` ENUM('admin', 'author')