Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Constraints Definition:

Constraints enforce rules at the table level, constraints prevent the deletion of a table if there are
They are stored in the data dictionary. They can be defined either table level or column level.
The following constraints types are valid:
----not null
----unique
----primary key
----foreign key
----check
1) not null constraint Definition:
If not null constraint defined on a column it will restrict the null values.

2) Unique constraint Definition:


If unique constraint defined on a column it will restrict the the duplicate values.

3) Primary key Constraint Definition:


If primary key constraint defined on a column it will restrict the null and duplicate values.

4) Foreign key Constraint Definition:

This constraint is used to define a relation between 2 tables called as entity relation or parent-chi
If a parent-child relation is defined, then the values which are not existing in the parent column w
Into the child column.

5) Check Constraint Definition:


This constraint is used to define an user defined condition, if check constraint defined on a colum
It will restrict the values which are not satisfying the condition.

On delete cascade Definition:


If a foreign key constraint is defined by using the on delete cascade, then
if a parent record is deleted automatically the child records are also deleted.

On delete set null Definition:


If a foreign key constraint is defined by using the on delete set null, then
if a parent record is deleted automatically the child records will be set to null.

Composite primary key or candidate key Definition:


A primary key that consists of 2 or more attributes which is known as composite key.
Or
A candidate key is a combination of one or more columns, the values of which uniquely identify e

Cascading constraints Definition:


The cascade constraints clause drops all referential integrity constraints
that refer to the primary and unique keys defined on the dropped columns.

Alter Table Examples

Adding , Dropping, Disabling and Enabling Constraints:


alter table table_name
constraint constraint_name constraint_type(column);

add
Adding Constraints

alter table table_name


ENABLE constraint constraint_name;

Enabling Constraints

alter table table_name


DISABLE constraint constraint_name;

Disabling Constraints

alter table table_name


drop constraint constraint_name;

Dropping Constraints

Viewing Constraints:
User_constraints table to view all constraint definitions and names

View the columns associated with the constraint names in the


user_cons_columns.

Referential Integrity:
Maintaining data integrity through a set of rules that restrict the values of
one or more columns of the tables based on the values of primary key or
unique key of the referenced table.

You might also like