Search code examples
sqlsql-servert-sqlcheck-constraint

Check SQL query like enum in MySQL


In MySQL I'm using enum and display variable with enum_range. How can I display check variable range in SQL Server if

roles VARCHAR(10) NOT NULL CHECK (roles IN('Admin', 'Staff', 'User'))

Solution

  • If you want to see the values, don't use either enum or check. Use foreign key constraints:

    create table Roles (
        RoleId int identity primary key,
        RoleName varchar(255)
    );
    
    insert into Roles(RoleName)
        values ('Admin'), ('Staff'), ('User');
    
    create table . . . (
        . . .
        RoleId int references Roles(RoleId),
        . . .
    );
    

    The shortcuts you want to use just get in the way of using the capabilities of the database.