Search code examples
mysqlcreate-table

MySQL - Create table Column with pre-defined insertacle value


I want to create a table which would have a column named Role where only 3 value can be inserted, "Admin","User","Customer".

So, what I have done is this-

CREATE TABLE Person
(
    PersonID int,
    Name varchar(255),
    Role varchar(10) IN ("Admin","User","Customer"),
    Address varchar(255),
    City varchar(255)
)

But it is giving me a error like it-

enter image description here

Can anyone please help?

Thanks in advance for helpipng :)


Solution

  • You can use enum datatype, as following: Check this url: enum mysql

    CREATE TABLE Person
        (
            PersonID int,
            Name varchar(255),
            Role enum("Admin","User","Customer"),
            Address varchar(255),
            City varchar(255)
        )