You are on page 1of 16

Data Integrity

TCS Internal
1
Objective

To be able to learn the concepts of data integrity , rules and


to implement various types of constraints.

TCS Internal
2
Scope

 Data Integrity concepts


 Defaults and rules
 Constraints
 IDENTITY property

TCS Internal
3
Data Integrity Concept
 The consistency and accuracy of the data stored in the
database with respect to the processes the system supports,
is referred as data integrity.
 Reasons for enforcing data integrity :
 To prevent invalid data entry into the database tables.
 To enforce the rules that are associated with the
information in the database.
 Data integrity in Conventional system Vs SQL Server

TCS Internal
4
Data Integrity Concept
 The consistency and accuracy of the data stored in the
database with respect to the processes the system supports,
is referred as data integrity.
 Reasons for enforcing data integrity :
 To prevent invalid data entry into the database tables.
 To enforce the rules that are associated with the
information in the database.
 Data integrity in Conventional system Vs SQL Server

TCS Internal
5
Data Integrity Concept

 Advantages of storing data integrity logic in the database :

 Single control point for database consistency.

 Simplifies maintenance.

 When rules need to be changed, change is required at only


one place- the SQL Server database itself.

 Less costlier to define rules at database level .

 Data integrity at this level is optimized for fast performance.

 All applications can take advantage of the global rules, rather


than building similar logic in each individual application.

 Need for rules at the client are eliminated since all rules are
stored with the data itself.

TCS Internal
6
Methods defining Data Integrity logic

 SQL Server offers two methods of defining data integrity logic on


the data :

 Create one global object and apply it to various parts of


data in the database. (Defaults and rules)

 Create and apply data integrity logic at the object


creation level. (Constraints).

TCS Internal
7
Types of Data Integrity

 There are three types of Data integrity :

 Entity integrity
 Domain integrity
 Referential integrity

TCS Internal
8
Entity Integrity

 Requires that all rows in a table have a unique


identification value, the primary key value.

 Lack of primary key restricts the usefulness of data, as


its elements would not be uniquely retrieved.

 Searches or statistical analysis may be meaningless if


record exists that are not uniquely identifiable.

 Primary key value can be changed and the whole row


can also be deleted, both of which depend on the level of
integrity required between the primary key and foreign
key references.

 Entity integrity is enforced through indexes, UNIQUE


constraints or PRIMARY KEY constraints.

TCS Internal
9
Domain Integrity

 Specifies a set of permissible or possible data values that are


valid for that field

 Also determines whether null values are allowed.

 Enforced through the use of validity checking.

 Also enforced by restricting the type ( through datatypes), the


formats of the columns (rules and constraints )or the range of
possible values ( rules, FOREIGN KEY and check constraints).

TCS Internal
10
Referential Integrity

 Refers to consistency among tables.

 Ensures that the relationships among the primary keys ( in the


referenced table) and foreign keys ( in the referencing tables) are
always maintained.

 Ensures that key values are consistent.

 Requires that there be no references to non-existent values.

 A row in the referenced table can not be deleted, if a foreign key


exists that refer to the row.

 Similarly, primary key in the referenced table also can not be


changed, if a foreign key exists that refer to the row.

 It would result in orphaned records. A foreign key value can not


be inserted into the referencing table, if no row with the
corresponding primary key exists in the referenced table.

TCS Internal
11
Enforcing data Integrity

 Enforcing data integrity involves preserving the consistency and


correctness of the data stored in the database by :

 validating the contents of individual fields.


 verifying field values with respect to one another.
 validating data in file or table as compared to another file
or table.
 verifying the successful and accurate updation of the
database for each transaction.

 Enforcement of data integrity can be categorized into:

 procedural data integrity


 declarative data integrity.

TCS Internal
12
Procedural data Integrity

 Implemented using triggers, stored procedures and views.

 Triggers enforce procedural data integrity because they are


automatically fired.

 Views and stored procedures do not directly support data


integrity, but help in maintaining and supporting data
integrity.

TCS Internal
13
Declarative data Integrity

 Declared as a part of the database definition.

 More concise and less error prone than procedural data integrity.

 Integrity checking is performed by DBMS, not by rules, stored


procedures or triggers.

 Declarative constraints are directly defined on the tables and


columns with CREATE TABLE / ALTER TABLE statements.

 Enforced through the use of constraints that restrict the data


values that can be inserted into the database or as the result of
an update.

TCS Internal
14
IDENTITY Property

 Used to create columns called identity columns that contain system-


generated values.

 The system generated values uniquely identify each row inserted into
the table.

 This feature can be used to generate sequential number (for example,


Member Number)

 SQL Server automatically generates a value based on

 the previous identity value


 the increment specified for the column in the table definition.
 IDENTITY property can be placed on any column and in any sequence.

 Only one identity column can be created per table.

 Syntax:
IDENTITY [ ( seed, increment) ]

TCS Internal
15
Summary

 Data Integrity concepts


 Defaults and rules
 Constraints
 IDENTITY property

TCS Internal
16

You might also like