Oracle Tutorial

What is Oracle
SQL Keywords

Oracle Wildcards

Oracle Wildcards

Oracle Aliases

Oracle Aliases

MySQL Tutorial

MySQL Tutorial

PL/SQL Tutorial

PL/SQL Tutorial

Oracle Interview Questions

Oracle Interview Questions and Answers


Oracle CHECK Constraint

In Oracle, CHECK constraint controls the values in the associated column. In other words, CHECK constraints ensures that the value in a certain column satisfy a boolean expression or not.

Oracle CHECK Constraint example

The following Oracle, creates a CHECK constraint on the "Age" column when the "tblCustomer" table is created. The CHECK constraint ensures that the customer's age greater or equal to 18 years:

Example

CREATE TABLE tblCustomer (
    custId int NOT NULL,
    firstName varchar(255) NOT NULL,
    lastName varchar(255) NOT NULL,
    Age int CHECK (Age>=18),
	PRIMARY KEY(custId)
);

Oracle CHECK Constraint on ALTER table example

The following Oracle, creates a CHECK constraint on the "Age" column when table already exists into the database:

Example

ALTER TABLE tblCustomer
ADD CONSTRAINT CHK_CustomerAge CHECK (Age>=18);

Oracle DROP a CHECK Constraint example

The following Oracle, dropping CHECK constraint "UC_Customer" from "tblCustomer" table:

Example

ALTER TABLE tblCustomer
DROP CONSTRAINT CHK_CustomerAge;