Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BD / Labs / English / Lab2 - Integrity constraints.doc
Скачиваний:
22
Добавлен:
20.02.2016
Размер:
217.09 Кб
Скачать

Laboratory work 2

Integrity constraints in SQL Oracle

Contents

1. Purpose of the lab 1

2. Theoretical backgrounds 1

2.1. Syntax 2

2.2. Purpose 2

2.3. Prerequisites 2

2.4. Keywords and Parameters 3

3. Lab tasks 5

4. Control questions 8

5. Appendices 9

5.1. Appendix. Conditions in SQL Oracle 9

5.1.1. Simple Comparison Conditions 9

5.1.2. Group Comparison Conditions 10

5.1.3. Membership Conditions 11

5.1.4. Range Conditions 11

5.1.5. NULL Conditions 11

5.1.6. EXISTS Conditions 11

5.1.7. LIKE Conditions 11

5.1.8. Compound Conditions 11

5.2. Example of the tables creation 11

  1. Purpose of the lab

  • To study SQL Oracle integrity constraints possibilities.

  • To acquire practical skills in describing integrity constraints.

  1. Theoretical backgrounds

You can define integrity constraints to enforce business rules on data in your tables. Once an integrity constraint is enabled, all data in the table must conform to the rule that it specifies. If you subsequently issue a SQL statement that modifies data in the table, then Oracle ensures that the resulting data satisfies the integrity constraint. Without integrity constraints, such business rules must be enforced programmatically by your application.

There are the following types of integrity constraints in SQL Oracle:

[NOT] NULL 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 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 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.

FOREIGN KEY 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:

CHECK Constraints for complex integrity rules.

There are two syntactical forms to define integrity constraint: column constraint and table constraint.

Column constraint specify restrictions with respect to the values of concrete column. Table constraint specify restrictions with respect to the group of columns and defines out of column definition.

    1. Syntax

    1. Purpose

To define an integrity constraint. An integrity constraint is a rule that restricts the values for one or more columns in a table. There

    1. Prerequisites

Constraint clauses can appear in either CREATE TABLE or ALTER TABLE statements. To define an integrity constraint, you must have the privileges necessary to issue one of these statements.

To create a referential integrity constraint, the parent table must be in your own schema, or you must have the REFERENCES privilege on the columns of the referenced key in the parent table.

Соседние файлы в папке English