Limit SQL Server column to a list of possible values

前端 未结 3 1523
盖世英雄少女心
盖世英雄少女心 2021-02-05 00:52

How do I put a constraint on a column so that it can only contain the following values? What do you call this type of constraint?

Allowed values: \"yes\", \"no\"         


        
3条回答
  •  悲哀的现实
    2021-02-05 01:28

    you can use a CHECK constraint

    ALTER TABLE 
    ADD CONSTRAINT chk_val CHECK (col in ('yes','no','maybe'))
    

    MSDN link

    提交回复
    热议问题