Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check Constraint

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 259
    Comment on it

    Check Constraint:

    It is used to restrict the range of values that can be inserted in a column. If a column contain check constraint then only a particular range of values can be inserted in that column.

    Example:

    CREATE TABLE Employee(
           Emp_ID   INT              NOT NULL,
           Emp_NAME VARCHAR (20)     NOT NULL,
           Emp_AGE  INT              NOT NULL CHECK (Emp_AGE >= 18),
           Emp_ADDRESS  CHAR (25) ,
           Emp_SALARY   DECIMAL (18, 2),       
           PRIMARY KEY (Emp_ID)
    );

    In this example we have put check constraint on Emp_Age column and we cannot insert Employee whose age is less than 18.

    Adding Check Constraint using Alter Command:

    We can easily add Check constraint  using Alter command.

    ALTER TABLE Employee
       ADD CONSTRAINT myCheck CHECK (Emp_AGE >= 18 );
    

    Drop a Check Constraint:

    ALTER TABLE Employee
       DROP CONSTRAINT myCheck;

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: