0% found this document useful (0 votes)
12 views26 pages

DBMS Unit 2

The document discusses relational model constraints in databases, which are rules that ensure data integrity during operations like insertion and updating. It outlines various types of constraints including domain, key, entity integrity, and referential integrity constraints, each serving to maintain the quality and consistency of the data. Additionally, it introduces relational algebra, detailing operations such as selection, projection, and join, which are used to manipulate and query data in relational databases.

Uploaded by

soumadipkundu05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views26 pages

DBMS Unit 2

The document discusses relational model constraints in databases, which are rules that ensure data integrity during operations like insertion and updating. It outlines various types of constraints including domain, key, entity integrity, and referential integrity constraints, each serving to maintain the quality and consistency of the data. Additionally, it introduces relational algebra, detailing operations such as selection, projection, and join, which are used to manipulate and query data in relational databases.

Uploaded by

soumadipkundu05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

DBMS

Unit - 2
Relational Model Constraints

● These are the restrictions or sets of rules imposed on the database


contents.
● It validates the quality of the database.
● It validates the various operations like data insertion, updation,
and other processes that have to be performed without affecting
the integrity of the data
Types of Constraints

● Domain constraints
● Key constraints or Uniqueness Constraints
● Entity Integrity constraints
● Referential integrity constraints
Types of Constraints
Domain Constraints

● Every attribute has a type:


integer, float, date, boolean, string, etc.
● An attribute can have a domain. E.g.:
Id > 0
Salary > 0
age < 100
City in {Irvine, LA, Riverside}
● An insertion can violate the domain constraint.
DBMS checks if insertion violates domain constraint
and reject the insertion.
Domain Constraints
Key Constraints or Uniqueness Constraints

● These are called uniqueness constraints since it ensures that every


tuple in the relation should be unique.
● Null values are not allowed in the primary key, hence Not Null
constraint is also part of the key constraint.
● A relation can have multiple keys or candidate keys(minimal
superkey), out of which we choose one of the keys as the primary
key, we don’t have any restriction on choosing the primary key out
of candidate keys, but it is suggested to go with the candidate key
with less number of attributes.
Key Constraints or Uniqueness Constraints
Entity Integrity Constraints

● Entity Integrity constraints say that no primary key can take a


NULL value, since using the primary key we identify each tuple
uniquely in a relation.
Entity Integrity Constraints
Referential Integrity Constraints

● The Referential integrity constraint is specified between two


relations or tables and used to maintain the consistency among the
tuples in two relations.
● This constraint is enforced through a foreign key, when an
attribute in the foreign key of relation R1 has the same domain(s)
as the primary key of relation R2, then the foreign key of R1 is said
to reference or refer to the primary key of relation R2.
● The values of the foreign key in a tuple of relation R1 can either
take the values of the primary key for some tuple in relation R2, or
can take NULL values, but can’t be empty.
Referential Integrity Constraints
Relational Algebra

● Relational algebra consists of a certain set of rules or


operations that are widely used to manipulate and query
data from a relational database.
● Relational algebra consists of various operators that help
us fetch and manipulate data from relational tables in the
database to perform certain operations on relational data.
Relational Algebra

● Selection(σ)
● Projection(π)
● Union(U)
● Set Difference(-)
● Set Intersection(∩)
● Rename(ρ)
● Cartesian Product(X)
● Join (⋈)
Selection(σ)

Select operation chooses the subset of tuples from the


relation that satisfies the given condition.

Notation: σc(R)
σ Team = 'A'
(Student)
Projection(π)

This operation selects certain required attributes, while


discarding other attributes. Projection in DBMS is a
process of selecting some specific attribute/columns from
a table while excluding the other attributes/columns from a
selected table.

Notation : πA (R)
πName Salary (Employees)
Union(U)
Set Difference(-)
Set Intersection(∩)
Cartesian Product(X)
Join (⋈)
● JOIN is used to combine related tuples from two
relations R and S.
● In its simplest form the JOIN operator is just the cross
product of the two relations and is represented as (R ⋈
S).
● JOIN allows you to evaluate a join condition between the
attributes of the relations on which the join is
undertaken.

The notation used is R ⋈ Join Condition S


Join (⋈)

R⋈ cS = σc(R X S)
Join condition C is of the form:
<cond_1> AND <cond_2> AND … AND <cond_k>
Each cond_i is of the form A op B, where:
A is an attribute of R, B is an attribute of S
op is a comparison operator: =, <, >, , , or .

Different types:
● Theta-join
● Equi-join
● Natural join

You might also like