Database Reference
In-Depth Information
20.1
What Are Constraints?
A
, as the word implies, constrains or applies a rule to an object or
a part of an object. In Oracle Database 10
constraint
, constraints are used to restrict
values in tables or make validation checks on one or more columns in a
table, or check values between columns in different tables.
g
20.1.1
Types and Uses of Constraints
There are two levels of constraints you can place on relational tables:
Inline Constraint
. A constraint that applies to an individual column
in a table.
Out-of-Line Constraint
. A constraint that applies to a table as a
whole or to multiple columns in a table.
The six types of constraints are listed as follows. Some of these are
always inline constraints, whereas others can be either inline or out-of-line,
depending on how they are defined.
NOT NULL
. This constraint is always an inline constraint and will
produce an error if no value is placed into this column when you
insert or update a row in the table.
Unique
. Enforces uniqueness on a column value and can be inline or
out of line. When you create a unique constraint, Oracle Database
10
will create an internal unique index if no index is available to
enforce the constraint. Whenever you insert a row or update a row,
the value in the column belonging to a unique constraint is verified as
being different from any other value in the column for every other
row in the table. You can define a unique constraint that checks more
than one column. In this case, the value of both columns combined
must be unique.
g
Note:
A unique column does not have to be declared as NOT NULL, but
it should be. Null values in a column are considered identical by the unique
constraint, so allowing unique constraints to be nullable is probably poor
design practice.
Search WWH ::




Custom Search