Sie sind auf Seite 1von 7

Data Integrity

Database System
Concepts
15.1
Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Data Integrity
Ensuring the integrity of the organization's databases is a key component of the
DBA's job. A database is of little use if the data it contains is inaccurate or if it
cannot be accessed due to integrity problems. The DBA has many tools at his
disposal to ensure data integrity.
Database structure integrity The DBMS uses internal structures and pointers
to maintain database objects in the proper order
Semantic data integrity Semantic data integrity deals with the DBMS features
and processes that can be used to ensure the accuracy and viability of the data
contents of a database
Structural database integrity refers to the consistency of the "holders" of the
data (the database objects), semantic data integrity refers to the consistency of
the data itself

System Concepts
15.2
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Types of Structural Problems


One common problem experienced by relational databases is index corruption.If the pointers do not point to the correct data, the index is useless.

Another, though somewhat rare, database structural integrity problem is table


data page header corruption.
Each individual physical page (or block) in the database file stores
housekeeping information, known as the header, at the beginning of the page.
This header enables the DBMS to easily and rapidly read the page contents. If
the header becomes corrupted, the DBMS may not be able to interpret the data
stored on the page (recovery from backup)

Backup files are another potential area for a structural integrity problem. Each
DBMS formats and maintains a specific structure for its database backup files. If
the backup file is not formatted correctly, or if data is in the wrong location in the
backup file, it cannot be used by the DBMS for recovery purposes. Media
failures, tape degradation, and bugs can cause such problems.

System Concepts
15.3
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Managing Structural Problems


Sybase and Microsoft SQL Server provide the DBCC utility program, DB2
supplies the CHECK and REPAIR utilities, and Informix offers the TBCHECK
utility.

Use extreme care when running the DBCC utility.

System Concepts
15.4
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Managing Structural Problems


DBCC utility.- Consistency Options
DBCC CHECKTABLE(table_name)
DBCC REINDEX(table_name)

Database Checking
DBCC CHECKDB(database_name)
DBCC CHECKCATALOG(database_name)
DBCC CHECKALLOC(database_name)

Memory Usage
DBCC MEMUSAGE
The DBCC command can be used to monitor current memory allocation and
usage.
System Concepts
15.5
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Semantic data integrity refers to the consistency of the data itself.

When DBMS facilities are used to enforce data integrity, less code needs to be
written, and therefore less code needs to be tested. This can reduce the time
and cost to get the "product" out the door.

Many forms of semantic data integrity can be enforced by using features of the
DBMS

System Concepts
15.6
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Entity Integrity means that each occurrence of an entity must be uniquely
identifiable. Requires the specification of a primary key

Unique Constraints The values stored in the column, or combination of


columns, must but unique within the table.
Each table can have zero, one, or many unique constraints consisting of one or
more columns each

Data Types Data type and data length are the most fundamental integrity
constraints; specifying the data type for each column when a table is created,
the DBMS will automatically ensure that only the correct type of data is stored in
that column.
User-Defined Data Types provides a mechanism for extending the type of
data that can be stored in databases and the way that the data is treated

System Concepts
15.7
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Default Values Each column can have only one default value.

Check Constraints is a DBMS-defined restriction placed on the data values


that can be stored in a column or columns of a table
The constraint name identifies the check constraint to the database. The same
constraint name cannot be specified more than once for the same table. If a
constraint name is not explicitly coded, the DBMS automatically generates a
unique name for the constraint
Check Constraint Benefits .The ability to enforce business rules directly into the database without requiring
additional application logic.
DBAs can implement check constraints without involving the application
programming staff
Check constraints provide better data integrity.

System Concepts
15.8
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Rules Sybase and Microsoft SQL Server both offer a special type of check
constraint called a rule. Although rules are similar to check constraints, they are
"free-standing" database objects.
Class work.- How to implement a default in SQL Server "free-standing"
database objects

Triggers Triggers are event-driven specialized procedures that are attached to


database tables. A trigger is a piece of code that is executed in response to a
data modification statement; that is, an INSERT, UPDATE, or DELETE.
Triggers are quite flexible and can be coded to suit many purposes. For
example, triggers can
Access and modify other tables
Print informational messages
Specify complex restrictions

System Concepts
15.9
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Triggers can be coded to fire at two different times: before the firing activity
occurs or after the firing activity occurs. A "before" trigger executes before the
firing activity occurs; an "after" trigger executes after the firing activity occurs.

Nested Triggers As we've already learned, a trigger is fired by an INSERT,


UPDATE, or DELETE. However, a trigger also can contain INSERT, UPDATE,
and DELETE statements within itself. Therefore, a data modification fires a
trigger that can cause another data modification that fires yet another trigger.
When a trigger contains INSERT, UPDATE, and/or DELETE logic, the trigger is
said to be a nested trigger.

System Concepts
15.10
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity

System Concepts
15.11
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Referential Integrity is a method for ensuring the "correctness" of data.

Referential integrity guarantees that an acceptable value is always in the foreign


key column.

System Concepts
15.12
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Referential Integrity Rules

Pendant DELETE
processing cannot
be implemented
using declarative
RI.
System Concepts
15.13
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Semantic Data Integrity


Referential Integrity Using Triggers If the DBMS you are using does not
provide the declarative RI functionality required by your applications, triggers
can be coded in lieu of declarative RI. By using triggers, it is possible to support
all conceivable RI rules.

Nested and recursive triggers can be coded to support a very robust


implementation of referential integrity.

System Concepts
15.14
Database Administration:
The Complete Guide to Practices and Procedures

Silberschatz, KorthCraig
and Sudarshan
S. Mullins

Das könnte Ihnen auch gefallen