Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
40
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Overview of Integrity Constraints

Figure 3–2 Table with a UNIQUE Key Constraint

Table DEPARTMENTS

DEPID

DNAME

LOC

10

Administration

1700

20

Marketing

1800

30

Purchasing

1700

40

Human Resources

2400

 

 

 

INSERT

INTO

50 MARKETING 1700

60

2400

UNIQUE Key Constraint

(no row may duplicate a value in the constraint's column)

This row violates the UNIQUE key constraint, because "MARKETING" is already present in another row; therefore, it is not allowed in the table.

This row is allowed because a null value is entered for the DNAME column; however, if a NOT NULL constraint is also defined on the DNAME column, this row is not allowed.

Note: You cannot have identical values in the non-null columns of a composite UNIQUE key constraint (UNIQUE key constraints allow NULL values).

Some examples of good unique keys include:

An employee social security number (the primary key might be the employee number)

A truck license plate number (the primary key might be the truck number)

A customer phone number, consisting of the two columns AREA_CODE and LOCAL_PHONE (the primary key might be the customer number)

A department name and location (the primary key might be the department number)

Constraints On Views: for Performance, Not Data Integrity

The constraints discussed throughout this chapter apply to tables, not views.

Maintaining Data Integrity Through Constraints 3-7

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