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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 731
    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:

    1. CREATE TABLE Employee(
    2. Emp_ID INT NOT NULL,
    3. Emp_NAME VARCHAR (20) NOT NULL,
    4. Emp_AGE INT NOT NULL CHECK (Emp_AGE >= 18),
    5. Emp_ADDRESS CHAR (25) ,
    6. Emp_SALARY DECIMAL (18, 2),
    7. PRIMARY KEY (Emp_ID)
    8. );

    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.

    1. ALTER TABLE Employee
    2. ADD CONSTRAINT myCheck CHECK (Emp_AGE >= 18 );
    3.  

    Drop a Check Constraint:

    1. ALTER TABLE Employee
    2. DROP CONSTRAINT myCheck;

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: