i want to check for a particular set of values.
eg
There is quite a wealth of information in the SQL Server documentation on this, but the two statements to create the check constraints you ask for are:
ALTER TABLE tablename ADD CONSTRAINT constraintName CHECK (colname between 1 and 5);
ALTER TABLE tablename ADD CONSTRAINT constraintName CHECK (colname in (1,2,4));
The condition of a check constraint can include:
A list of constant expressions introduced with in
A range of constant expressions introduced with between
A set of conditions introduced with like, which may contain wildcard characters
This allows you to have conditions like:
(colname >= 1 AND colname <= 5)
ALTER TABLE tablename ADD CONSTRAINT constraintName CHECK (colname in (1,2,4));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.