This Oracle tutorial explains how to use the check constraints in Oracle with syntax and examples.
A check constraint allows you to specify a condition on each row in a table.
The syntax for creating a check constraint using a CREATE TABLE statement in Oracle is:
The DISABLE keyword is optional. If you create a check constraint using the DISABLE keyword, the constraint will be created, but the condition will not be enforced.
In this first example, we've created a check constraint on the suppliers table called check_supplier_id. This constraint ensures that the supplier_id field contains values between 100 and 9999.
In this second example, we've created a check constraint called check_supplier_name. This constraint ensures that the supplier_name column always contains uppercase characters.
The syntax for creating a check constraint in an ALTER TABLE statement in Oracle is:
The DISABLE keyword is optional. If you create a check constraint using the DISABLE keyword, the constraint will be created, but the condition will not be enforced.
In this example, we've created a check constraint on the existing suppliers table called check_supplier_name. It ensures that the supplier_name field only contains the following values: CISCO, GCP, or MICRO.
The syntax for dropping a check constraint is:
In this example, we're dropping a check constraint on the suppliers table called check_supplier_id.
The syntax for enabling a check constraint in Oracle is:
In this example, we're enabling a check constraint on the suppliers table called check_supplier_id.
The syntax for disabling a check constraint in Oracle is:
In this example, we're disabling a check constraint on the suppliers table called check_supplier_id.