1ALTER TABLE <table>
2ADD CONSTRAINT chk_val CHECK (col in ('yes','no','maybe'))
1CREATE TABLE Persons (
2 ID int NOT NULL,
3 LastName varchar(255) NOT NULL,
4 FirstName varchar(255),
5 Age int,
6 City varchar(255),
7 CONSTRAINT CHK_Person CHECK (Age>=18 AND City='Sandnes')
8);
1CREATE TABLE test(
2 _id BIGINT PRIMARY KEY NOT NULL,
3 decision NVARCHAR(5),
4 CHECK (decision in ('yes','no','maybe'))
5);
1#Add Check
2ALTER TABLE Persons
3ADD CONSTRAINT CHK_PersonAge CHECK (Age>=18 AND City='Sandnes');
4
5#Drop Check
6ALTER TABLE Persons
7DROP CHECK CHK_PersonAge;
1#For one column
2CREATE TABLE Persons (
3 ID int NOT NULL,
4 LastName varchar(255) NOT NULL,
5 FirstName varchar(255),
6 Age int CHECK (Age>=18)
7);
1/*Adding Check constraint in sql server*/
2ALTER TABLE (Table_Name)
3ADD CONSTRAINT (Constraint_Name) CHECK (Boolean_Expression)