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);
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)