Professional Documents
Culture Documents
Page 1 of 77
Database Administration: The Complete Guide to DBA Practices and Procedures, Second Edition
⏭
PREV NEXT
⏮
12. Application Performance 14. Database Security
TYPES OF INTEGRITY
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 2 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 3 of 77
⬆
If the pointers do not point to the
correct data, the index is useless.
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 4 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 5 of 77
⬆
the CHECK and REPAIR utilities, and
Informix offers the TBCHECK utility.
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 6 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 7 of 77
Consistency Options
• DBCC CHECKTABLE(table_name)
checks the consistency of the data and
index pages of a table. When DBCC is
run using this option, it will report on
the number of data pages, the number
of rows, the number of text and image
columns, as well as any integrity
violations.
The
The DB2
DB2 REPAIR
REPAIR Utility
Utility
The REPAIR utility is designed to modify DB2 data and associated data structures when there is an
error or problem. You can use the REPAIR utility to perform tasks such as testing DBD definitions,
repairing DBDs by synchronizing with the system catalog metadata, resetting pending states,
producing dumps, and surgically replacing specific data areas of tablespaces and indexes (among
other functions).
As with all database structural integrity utilities, care should be taken when using the REPAIR utility.
Furthermore, it is wise first to consult with your DBMS support center (in this case, IBM) before
running such utilities. Certain options of the REPAIR utility can damage your database and the data
stored therein if used improperly.
• DBCC REINDEX(table_name)
defragments the indexes built on the
specified table.
Database Checking
• DBCC CHECKDB(database_name)
runs CHECKTABLE (see above) on
every table in the database. This
option checks the consistency of the
data and index pages of all defined
tables.
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 8 of 77
• DBCC CHECKCATALOG
(database_name) checks the
consistency of the system catalog
tables for the specified database. It
will report on the size and number of
segments used, as well as detect and
report on any integrity errors.
• DBCC CHECKALLOC
(database_name) checks the
consistency of the specified database
and reports on the current extent
structure. The CHECKALLOC option
may find spurious allocation problems
if DBCC is run while transactions are
modifying the database. This option
also reports on the number of
allocations and the pages used per
allocation.
• DBCC CHECKFILEGROUP
(filegroup_name) checks the
allocation and structural integrity of
all tables and indexed views in the
specified database and issues a report
of the findings.
Memory Usage
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices and ... Page 9 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 10 of 77
Additional Options
⬆
important issue and is debated often.
In general, using DBMS features to
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 11 of 77
⬆
the DBMS.
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 12 of 77
SQL
SQL Server
Server 2012
2012 Semantic
Semantic Integrity
Integrity
Microsoft SQL Server 2012 includes several features for managing semantic integrity and data quality.
Perhaps the most intriguing featuring is Data Quality Services (DQS), which facilitates the ability for
data professionals to maintain the quality of their data and ensure that the data is suited for the
business purpose. DQS is a knowledge-driven solution that provides both computer-assisted and
interactive ways to manage the integrity and quality of SQL Server data. DQS enables you to discover,
build, and manage knowledge about your data. You can then use that knowledge to perform data
cleansing, matching, and profiling. You can also leverage the cloud-based services of reference data
providers in a DQS data quality project.
• Data cleansing
• Data matching
• Profiling
• Monitoring
• Knowledge base
SQL Server also features Master Data Services for the management of master data. Using Microsoft
SQL Server Master Data Services, a data professional can ensure the integrity of information and
consistency of data across different applications. The Master Data Services software helps to ensure
quality in a master data hub using rules and automated workflows.
Before investigating third-party software solutions for semantic data integrity, be sure you thoroughly
investigate the functionality and feature set of your in-house DBMS products. Many contain features
that can be used to improve the quality and integrity of your database data.
Entity Integrity
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 13 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 14 of 77
Unique Constraints
⬆
columns, must be unique within the
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 15 of 77
Data Types
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 16 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 17 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 18 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 19 of 77
Default Values
⬆
default value. The column’s data type,
length, and property must be able to
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 20 of 77
Check Constraints
⬆
A check constraint is a DBMS-defined
restriction placed on the data values
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 21 of 77
⬆
well as BETWEEN, IN, LIKE, and
NULL. Furthermore, AND and OR
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 22 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 23 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 24 of 77
⬆
emp_type CHAR(8)
CHECK (emp_type IN ('temp', 'fulltime', 'contract')),
emp_dept CHAR(3) NOT NULL WITH DEFAULT,
salary DECIMAL(7,2) NOT NULL
CONSTRAINT check_salary
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 25 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 26 of 77
⬆
emp_type CHAR(8)
CHECK (emp_type IN ('temp', 'fulltime', 'contract')),
emp_dept CHAR(3) NOT NULL WITH DEFAULT,
salary DECIMAL(7,2) NOT NULL
CONSTRAINT check_salary
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 27 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 28 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 29 of 77
Rules
Rules
Both Sybase and Microsoft SQL Server offer a special type of check constraint called a rule. Although
rules are similar to check constraints, they are “freestanding” database objects.
Like a check constraint, a rule defines the parameters for data validation. Whenever data is inserted or
updated, the rule is checked to ensure that the data modification complies with the rule. Both columns
and UDTs can have rules defined for them.
After a rule has been created, it must be bound to columns and UDTs before it has any effect on the
database. Binding is accomplished using the SP_BINDRULE system procedure. For example, the
following statements can be used to create a rule that forces the state code to represent only Illinois,
Wisconsin, or Indiana, and then binds the rule to the state column in two different tables:
Once a rule is bound to a column or user-defined data type, it will function like a check constraint.
Whenever data values are inserted or updated, the rule will be invoked to ensure that the values
conform to the rule definition. Rules can be removed from columns or user-defined data types by
using the SP_UNBIND system procedure when the rule is no longer required.
Rules can be more reliable than check constraints because a rule need be created only once, after
which it is bound to the appropriate columns and data types. So, if one constraint applies to multiple
columns, less work is required with a rule than with a check constraint. The check constraint must be
explicitly coded within the DDL of every table that must be checked.
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 30 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 31 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 32 of 77
Triggers
⬆
modification statement.
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 33 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 34 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 35 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 36 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 37 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 38 of 77
Nested Triggers
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 39 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 40 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 41 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 42 of 77
A Sample Trigger
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 43 of 77
Trigger Granularity
⬆
trigger, once fired, is executed once
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 44 of 77
INSTEAD OF Triggers
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 45 of 77
Trigger Synopsis
⬆
Triggers are a powerful feature of
modern DBMS products. Triggers
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 46 of 77
Referential Integrity
⬆
primary and foreign key columns and
the rules that dictate the data that can
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 47 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 48 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 49 of 77
INSERT Rule
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 50 of 77
UPDATE Rule
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 51 of 77
DELETE Rule
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 52 of 77
Pendant DELETE
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 53 of 77
Setting Up Relationships
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 54 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 55 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 56 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 57 of 77
• DELETE RESTRICT
• DELETE CASCADE
• DELETE NEUTRALIZE
• UPDATE RESTRICT
• UPDATE CASCADE
• UPDATE NEUTRALIZE
• INSERT RESTRICT
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 58 of 77
⬆
this type of constraint is with a trigger.
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 59 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 60 of 77
⬆
IF UPDATE (title_id)
IF (select count(*)
FROM deleted, titles
WHERE deleted.title_id = title.titleid) = 0
BEGIN
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 61 of 77
UPDATE titleauthor
SET titleauthor.titleid = null
FROM titleauthor, deleted
WHERE titleauthor.titleid = deleted.title_id
END
RETURN
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 62 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 63 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 64 of 77
RI Rules of Thumb
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 65 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 66 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 67 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 68 of 77
⬆
BUS_START DATE NOT NULL,
BUS_END DATE NOT NULL,
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 69 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 70 of 77
SELECT Price
FROM Course FOR BUSINESS_TIME AS OF '2012-04-03'
WHERE Title = 'ENGLISH 101';
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 71 of 77
UPDATE Course
FOR PORTION OF BUSINESS_TIME FROM '2011-11-01' TO '2012-02-02'
SET Price = 325.00
WHERE CourseNo = 100;
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 72 of 77
SUMMARY
⬆
features to support data integrity.
Because one of the major problems
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 73 of 77
REVIEW ⬆
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 74 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 75 of 77
SUGGESTED READING
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 76 of 77
Recommended / Playlists / History / Topics / Tutorials / Settings / Get the App / Sign Out ⬆
© 2018 Safari. Terms of Service / Privacy Policy
NEXT
⏮
PREV
⏭
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018
13. Data Integrity - Database Administration: The Complete Guide to DBA Practices a... Page 77 of 77
mhtml:file://D:\database_administration__the_complete_guide_to_dba_practices_and_proc... 4/2/2018