Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / Database concepts.pdf
Скачиваний:
29
Добавлен:
12.05.2015
Размер:
6.96 Mб
Скачать

Introduction to Data Integrity

Introduction to Data Integrity

It is important that data adhere to a predefined set of rules, as determined by the database administrator or application developer. As an example of data integrity, consider the tables employees and departments and the business rules for the information in each of the tables, as illustrated in Figure 21–1.

Figure 21–1 Examples of Data Integrity

Table DEPT

DEPTNO

DNAME

LOC

20

RESEARCH

DALLAS

30

SALES

CHICAGO

 

 

 

Each row must have a value for the ENAME column

Each value in the DNAME column must be unique

Each value in the DEPTNO column must match a value in the DEPTNO column of the DEPT table

Table EMP

EMPNO

ENAME

... Other Columns ...

SAL

COMM

DEPTNO

6666

MULDER

 

5500.00

 

20

7329

SMITH

 

9000.00

 

20

7499

ALLEN

 

7500.00

100.00

30

7521

WARD

 

5000.00

200.00

30

7566

JONES

 

2975.00

400.00

30

Each row must have a value for the EMPNO column, and the value must be unique

Each value in the SAL column must be less than 10,000

Note that some columns in each table have specific rules that constrain the data contained within them.

21-2 Oracle9i Database Concepts

Introduction to Data Integrity

Types of Data Integrity

This section describes the rules that can be applied to table columns to enforce different types of data integrity.

Null Rule

A null is a rule defined on a single column that allows or disallows inserts or updates of rows containing a null (the absence of a value) in that column.

Unique Column Values

A unique value defined on a column (or set of columns) allows the insert or update of a row only if it contains a unique value in that column (or set of columns).

Primary Key Values

A primary key value defined on a key (a column or set of columns) specifies that each row in the table can be uniquely identified by the values in the key.

Referential Integrity Rules

A rule defined on a key (a column or set of columns) in one table that guarantees that the values in that key match the values in a key in a related table (the referenced value).

Referential integrity also includes the rules that dictate what types of data manipulation are allowed on referenced values and how these actions affect dependent values. The rules associated with referential integrity are:

Restrict: Disallows the update or deletion of referenced data.

Set to Null: When referenced data is updated or deleted, all associated dependent data is set to NULL.

Set to Default: When referenced data is updated or deleted, all associated dependent data is set to a default value.

Cascade: When referenced data is updated, all associated dependent data is correspondingly updated. When a referenced row is deleted, all associated dependent rows are deleted.

No Action: Disallows the update or deletion of referenced data. This differs from RESTRICT in that it is checked at the end of the statement, or at the end of the transaction if the constraint is deferred. (Oracle uses No Action as its default action.)

Data Integrity 21-3

Introduction to Data Integrity

Complex Integrity Checking

Complex integrity checking is a user-defined rule for a column (or set of columns) that allows or disallows inserts, updates, or deletes of a row based on the value it contains for the column (or set of columns).

How Oracle Enforces Data Integrity

Oracle enables you to define and enforce each type of data integrity rule defined in the previous section. Most of these rules are easily defined using integrity constraints or database triggers.

Integrity Constraints Description

An integrity constraint is a declarative method of defining a rule for a column of a table. Oracle supports the following integrity constraints:

NOT NULL constraints for the rules associated with nulls in a column

UNIQUE key constraints for the rule associated with unique column values

PRIMARY KEY constraints for the rule associated with primary identification values

FOREIGN KEY constraints for the rules associated with referential integrity. Oracle supports the use of FOREIGN KEY integrity constraints to define the referential integrity actions, including:

Update and delete No Action

Delete CASCADE

Delete SET NULL

CHECK constraints for complex integrity rules

Note: You cannot enforce referential integrity using declarative integrity constraints if child and parent tables are on different nodes of a distributed database. However, you can enforce referential integrity in a distributed database using database triggers (see next section).

21-4 Oracle9i Database Concepts

Соседние файлы в папке Oracle selected docs