SQL Constraints - Check Key Constraint - DotNet and DataBase

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Wednesday, 1 August 2018

SQL Constraints - Check Key Constraint

Check Key constraint is used to restrict the values in a column within the specified condition.
CREATE TABLE <Table Name> (
    <Column Name> data type CHECK(Condition)


CREATE TABLE Employees (
    ID int NOT NULL Primary Key IDENTITY(1,1),
    LastName varchar(255) NOT NULL UNIQUE,
    FirstName varchar(255),
    Age int CHECK(Age>17 and Age<61)

Now, it not possible to enter age less than 17 and greater than 60.

Using Alter command

ADD CHECK (Age>17 and Age<61);

No comments:

Post a comment


Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.