Adding check at the time of table creation

Posted by Abhisek under Sql Server category on | Views : 1411
The following syntax is used to add check to the table at the time of its creation.
CREATE TABLE<table_name> (col datatype, check(condition), col2 datatype,...)

More than one check constraints can be added to a single table. This will put a limitation to the values of an specific domain.

create table student(name char(20), age int check(age<=20))

The above code will add a constraint to the student table at the time of its creation to restrict the age value to 20.

Comments or Responses

Login to post response