0% found this document useful (0 votes)
20 views

Data Integrity

How we can ensure Data integrity DBMS

Uploaded by

paki.kakawzd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Data Integrity

How we can ensure Data integrity DBMS

Uploaded by

paki.kakawzd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Data Base Management System

Lecture 5

Mudassar Mahmood Mirza


Relational Data Integrity
 Data integrity means reliability and accuracy of data.
Integrity rules are designed to keep the data consistent and
correct. It is very important that a database maintains the
quality of the data stored in it. Data integrity is enforced
under the following categories
 Entity Integrity
 Domain integrity
 Referential Integrity
Entity Integrity
 The entity integrity rule ensures that the primary key
cannot contain null data. It is also called row integrity. If
primary key is allowed to have null value, it is not possible to
uniquely identify a row in the table. So entity integrity
defines a tuple as unique entity for a particular relation.
Domain Integrity
 A set of values that can be stored in a column is called a
domain. For example, the marks of a student in a subject can
be from 0 to 100 or CGPA from 0.0-4.0. Domain integrity
enforces restrictions on the values entered in a column. It
specifies the validity of a specific data entry in a column. The
data type of a column enforces domain integrity. For
example, if the data type of age column is numeric, it cannot
store a value like ‘Twenty Three’ instead of 23.
Referential Integrity
 Referential integrity ensures the validity or integrity of
relationship between tables when records are added or
deleted. It ensures that key values are consistent across the
tables. A value cannot be inserted in foreign key if it has no
corresponding value in primary key field of the relation table.
Such consistency requires that if a key value changes then all
references to it should also be changed accordingly. The value
in foreign key column in the referencing table must be same
as the value in the corresponding primary key column in
referenced /parent table.
Relational Algebra
 Relational algebra is a query language that processes one or
more relations to define another relation without changing
original relations.

 Unary Operations
 Binary Operations
Unary Operations
 The operations which involve only one relation are called
unary operation. The following operations are the unary
operations
 Selection
 Projection
Binary Operations
 The operations which involve pairs of relations are called
binary operations. A binary operation uses two relations as
input and produces a new relation as output. Binary
operations are
 Union
 Set Difference
 Cartesian Product
Unary Operation
 Selection Operation
 The selection operation is a unary operation. The selection operator
is sigma σ. It acts like a filter on a relation. It returns only a certain
number of tuples. It selects the tuples using a condition.
 σ CONDITION (R)
 Comparison Operation
= < > ≤ ≥ =/=
 Logical Operation
 (and) (or) (Not)
For Example
 Select a student where name is ALI from Student table.
 σ Name=’ALI’ (Student)
 Select a student where name is ALI and AGE is 24 from Student table.
 σ Name=’ALI’ Age=24 (Student)
 Select a student where name is ALI or AGE is 24 from Student table.
 σ Name=’ALI’ Age=24 (Student)
 Select a student where name is ALI and AGE is not 24 from Student
table.
 σ Name=’ALI’ Age =/= 24 (Student)
 Select a student where name is not ALI and AGE is not 24 from Student
table.
 σ (Name=’ALI’ Age = 24) (Student)
Projection
 Projection is also a unary operation. The projection operation is pi
π. It limits the attributes returned from the original relation.
 π ATTRIBUTE (Student)
 Select name and AGE from Student table.
 π Name,Age (Student)
 Select name Where AGE is 24 from Student table.
 π Name(σ Age =24 (Student))
 Select Name and Rollno of student where name is Ali or AGE is 24
from Student table.
 π Name,Rollno (σ Name=’Ali Age=24 (Student))
Binary Operation
 Union
 The Union operation of two relations combines the tuples of
both relations to produce a third relation. If two relations
contain identical tuples, the duplicate tuples are eliminated.
Union operation is commutative. The resulting relation has
the same degree as the original relation.
 A U B = B UA

 The relation on which the union operation is done must contains


equal no of attributes that is they must be union compatible
relation.
Example
Binary Operation
 Intersection.
 The Intersection operation works on two relations and
combines the tuples of both relations to produce a third
relation. Unlike union it produces a relation that only contains
common tuples. The degree of the resulting relation may be
equal to or less than the original relation.

 A ∩ B = B ∩A
Example

Result(B ∩A)
Difference
 The difference operation works on two relations. It produces
a relation that contains tuples that occur in the first relation
but not in second. Difference operation is not commutative.
 A - B =/= B - A
Example

You might also like