0% found this document useful (0 votes)
38 views70 pages

Relationalalgebra E

The document provides an overview of the relational model, which is the theoretical basis for relational databases. It describes key concepts such as relations (tables), attributes (columns), tuples (rows), and domains. It also covers relational algebra operations like selection and integrity constraints like entity, referential, and key constraints that help ensure data accuracy and consistency. The relational model represents data as mathematical relations and allows users to specify logical queries without specifying physical execution details.

Uploaded by

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

Relationalalgebra E

The document provides an overview of the relational model, which is the theoretical basis for relational databases. It describes key concepts such as relations (tables), attributes (columns), tuples (rows), and domains. It also covers relational algebra operations like selection and integrity constraints like entity, referential, and key constraints that help ensure data accuracy and consistency. The relational model represents data as mathematical relations and allows users to specify logical queries without specifying physical execution details.

Uploaded by

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

Relational Model

Introduction to Relational Model

• Relational Model is the theoretical basis of relational


databases.
• Relational Model of data is based on the concept of relations.
• A “Relation” is a mathematical concept based on the ideas of
sets
• The Relational Model was proposed by E.F. Codd from IBM in
1970 to model data in the form of relations or tables.
What is Relational Model?

 Relational Model represents how data is stored in Relational


Databases. A relational database stores data in the form of
relations(tables).
• After designing the conceptual model of database using E-R
diagram, we need to convert the conceptual model in the
relational model which can be implemented using any
RDBMS languages.
• RDBMS languages: Oracle, SQL, MySQL etc.
What is RDBMS?

 RDBMS stands for: Relational Database Management System. RDBMS


is the basis for SQL, and for all modern database systems like MS SQL
Server, IBM DB2, Oracle, MySQL and Microsoft Access.

 A RDBMS is a database management system (DBMS) that is based on


the relational model as introduced by E.F. Codd.

 Current popular RDBMS include:


o DB2 & Informix Dynamic Server – from IBM
o Oracle & Rdb – from Oracle
o SQL Server & MS Access – from Microsoft
Relational Model Concept

 Relational model can be represented as a table with columns and rows.


 Each row is known as a tuple.
 Each table of the column has a name or attribute.

Roll No. Name Phone_No.


1 Ajay 9955668756
2 Raj 8874895645
3 Vijay 8874568925
4 Aman 9587456523
Basic concepts
• Relation: A Relation is a table with columns and rows.
Collection of homogeneous tuples.
• Attribute: An attribute is a named column of a relation.
• Domain: There are set of allowable values for every
attribute, called its domain.
– Exp- Domain of roll number{10,11,23,56,78}
– Domain of branch{CSE,IT,ME,ECE}
• Tuple: Each row in a relation is called tuple.
• Relational Schema: A relational schema represents the
name of the relation with is attributes.
• Relation Instance: Relation instance is a finite set of tuples. Relation
instances never have duplicate tuples.
• Degree or Arity: Number of column or attributes in relation R.
• Cardinality: Number of rows or tuples in relation R.
• Relation Key: Every row has one or multiple attributes, that can
uniquely identify the row in the relation, which is called
relation(Primary Key).
• Tuple Variable: It is the data stored in a record of the table.
Properties of Relational Model

Each relation has unique name.


Each row/tuple is unique. No duplicate row.
Entries in any column have the same domain.
Each attribute/column has a unique name.
Order of the column or rows is irrelevant i.e. relations
are unordered.
Each cell of relation contains exactly one value i.e.
attribute values are required to be atomic.
Alternative Terminology of
Relational Model

Formal Terms Alternative 1 Alternative 2


Relation Table File
Tuple Row Record
Attribute Column Field
Integrity Constraints over Relation
 Integrity Constraints are used to ensure accuracy and consistency of the
data in a relational database.

 Integrity constraints are set of rules that the database is not permitted
to violate.

 Constraints may apply to each attribute or they may apply to


relationships between tables.

 Integrity constraints ensure that changes made to the database by


authorized users do not results in a loss of data consistency. Thus,
integrity constraints guard against accidental damage to the database.

 Example: A blood group must be ‘A or ‘B’ or ‘AB’ or ‘o’ only (Can not any
other value else).
Types of Integrity Constraints
• Domain Constraints
• Entity Integrity Constraints
• Referential Integrity Constraints
• Key Constraints
Domain Constrains

• Domain Constraints defines the domain or the valid set of values for an
attribute.
• The data type of domain includes string, character, integer, time, date,
currency, etc. The value of the attribute must be available in the
corresponding domain.

Student_ID Name Semester Age


101 Manish 1st 18
102 Rohit 3rd 19
103 Amrit 7th 20
104 Aman 5th A
Entity Integrity Constraints

 The entity integrity constraint states that primary key value can’t be null.
 This is because the primary key value is used to identified individual rows in relation
and if the primary key has a null value, then we can’t identify those rows.
 A table can contain a null value other than the primary key field.

Emp_ID Emp_Name Salary


111 Mohan 20000
112 Rohan 30000
113 Sohan 35000
Om 20000
Referential Integrity Constraints

 A referential integrity constraint is specified between two tables.


 It is enforced when a foreign key references the primary key of a table.
 In the Referential integrity constraints, if a foreign key in Table 1 refers to the primary
key of table 2, then either every value of the foreign key in table 1 must be available in
primary key value of table 2 or it must be null.
 The rules are:
• You cannot delete a record from a primary table if matching records exist
in a related table.
• You cannot change a primary key value in the primary table if that record
has related records.
• You cannot insert a value in the foreign key field of the related table that
does not exist In the primary key of the primary table.
• However, you can enter a Null value in the foreign key, specifying that the
records are unrelated.
Key Constraints

 An entity set can have multiple keys or candidate keys(minimal super key), but out of which one
key will be the primary key.
 Key constraints specifies that in any relation-
 All the values of primary key must be unique.
 The value of primary key must not be Null.

Student_ID Name Semester Age


101 Manish 1st 18
102 Rohit 3rd 19
103 Parkash 5th 20
102 Amrit 7th 21
Query Language
• Interface between the user and the data base.
• A query is a statement written in query language for
retrieval of data from database. Eg. SQL
• Query= “Retrieval Program”
Procedural vs. Non- Procedural

1. Procedural query language


• In procedural query language user instructs the system to perform a series of
operations to produce the desired results.
• Here users tells what data to be retrieved from database and how to retrieve it.

2. Non-Procedural query language


• In Non-procedural query language, user instructs the system to produce the
desired result without telling the step by step process.
• Here users tells what data to be retrieved from database but doesn’t tell how
to retrieve it.
Two “Pure” Query Language
• Two “Pure” Query Language or Two Mathematical
Query Language:
 Relational Algebra
 Relational Calculus
o Tuple Relational Calculus
o Domain Relational Calculus
Relational Algebra:
• Relational algebra is a conceptual procedural query language.
• It is more operational, very useful for representing execution
plans.
• Procedural: What data is required and how to get those data.

Relational Calculus:
• Relational calculus is a conceptual non-procedural query
language.
• It is non-operational or declarative.
• Non-Procedural: What data they want without specifying how to
get those data.
Relational Algebra

• Procedural Language(formal Query language)


• It is the base of SQL. It is used to make SQL.
• Relational Algebra is a system used to model data
stored in relational databases.
• It’s largely used as the theoretical basis for which
query languages like SQL are built around.
• It is a language to express relational queries.
INTRODUCTION
Select
• Select
• Select operation selects the rows that satisfy a given
predicate (condition).
• The Greek letter sigma is used to denote the
select operation.
• Syntax:
• Find the students from the student relation who belong
to qadian CITY.
BRANCH_NAME LOAN_NO AMOUNT

Downtown L-17 1000

Redwood L-23 2000

Perryride L-15 1500

Downtown L-14 1500

Mianus L-13 500

Roundhill L-11 900

Perryride L-16 1300

σ BRANCH_NAME="perryride" (LOAN)  
BRANCH_NAME LOAN_NO AMOUNT

Perryride L-15 1500

Perryride L-16 1300


Project

• Use to select attributes from the relation


NAME STREET CITY

Jones Main Harrison

Smith North Rye

Hays Main Harrison

Curry North Rye

Johnson Alma Brooklyn

Brooks Senator Brooklyn

∏ NAME, CITY (CUSTOMER)
NAME CITY

Jones Harrison

Smith Rye

Hays Harrison

Curry Rye

Johnson Brooklyn

Brooks Brooklyn
Rename

• Used for following


• 1. When we want to change the name of any existing
relation
• 2. When we want to give a name to a new relation
which is obtained as a result of any relational algebra
expression
ρ (new relaion)
(Relation)
•Query to rename the first attribute of the table Student with
attributes A, B, C to P. 
ρ (P, B, C) (Student)

•Query to rename the table name Project to Pro and its


attributes to P, Q, R. 
ρ Pro(P, Q, R) (Project)
•Query to rename the attributes Name, Age of table Department to
A,B. 
ρ (A, B) (Department)

•Query to rename the table name Loan to L.


ρ L (LOAN)
Cartesian Product

• Cartesian product is denoted by cross (×) and it


combines the information from any two relations.
• Cartesian product of two relations R and S is denoted
as R×S, which result in a new relation that contains all
the possible combinations of tuples in R and S.
• Degree or arity (P) = arity(R) + arity(S)

• Cardinality (P) = cardinality(R) * cardinality(S)


Union

• the union of two sets results in a new set that


contains all the elements belonging to both the sets
but does not include the duplicate elements
Regno Branch Section

1 CSE A

2 ECE B

3 MECH B

4 CIVIL A

5 CSE B

Regno Branch Section

1 CIVIL A

2 CSE A

3 ECE B

To display all the regno of R1 and R2, use the following command −
∏regno(R1) ∪ ∏regno(R2)
Regno
To retriev

5
Set Difference

• the difference of two sets results in a new set that


contains all the elements of first set which are
not present in the second set.
Example PERSON relation with attributes Name, Age, and FavoriteFood
If we have another table, Person3, we can take the difference of the Person
relation to Person3, to result in a single row table with Stacy.
Intersection

• Intersection of two sets results in a new set which


contains the common elements from both the sets.
Natural Join

• Join operation allows us to combine certain


selections and cartesian product into one operation.
• Example: Show all the customers who have an
account and also have taken a loan.
Outer Join

• Outer-join operation is an extension of natural join


which deals with missing information.
Division

• The division operation is suited to the queries that


include the phrase “for all”.

You might also like