SlideShare a Scribd company logo
DATABASE SYSTEMS
STAFF NAME : D.SARITHA
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER APPLICATIONS
BON SECOURS COLLEGE FOR WOMEN
THANJAVUR
UNIT : II
CHAPTER : 2
TOPIC : RELATIONAL MODEL
RELATIONAL MODEL
ROLL_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 9455123451 18
2 RAMESH GURGAON 9652431543 18
3 SUJIT ROHTAK 9156253131 20
4 SURESH DELHI 18
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).
Consider a relation STUDENT with attributes ROLL_NO, NAME,
ADDRESS, PHONE and AGE shown in Table
STUDENT
1 RAM DELHI 9455123451 18
IMPORTANT TERMINOLOGIES
1.Attribute: Attributes are the properties that define a relation.
e.g.; ROLL_NO, NAME
2.Relation Schema: A relation schema represents name of the relation with
its attributes.
e.g.; STUDENT (ROLL_NO, NAME, ADDRESS, PHONE and AGE) is
relation schema for STUDENT. If a schema has more than 1 relation, it is
called Relational Schema.
3.Tuple: Each row in the relation is known as tuple. The above relation
contains 4 tuples, one of which is shown as:
4.Relation Instance: The set of tuples of a relation at a particular instance
of time is called as relation instance.
ROLL_NO
1
2
3
4
5.Degree: The number of attributes in the relation is known as degree of the
relation. The STUDENT relation defined above has degree 5.
6.Cardinality: The number of tuples in a relation is known as cardinality.
The STUDENT relation defined above has cardinality 4.
7.Column: Column represents the set of values for a particular attribute.
The column ROLL_NO is extracted from relation STUDENT.
8.NULL Values: The value which is not known or unavailable is called NULL
value. It is represented by blank space.
e.g.; PHONE of STUDENT having ROLL_NO 4 is NULL.
Different Types of Keys in Relational Model
Super Key
The set of attributes which can uniquely identify a tuple is known
as Super Key.
For Example, STUD_NO, (STUD_NO, STUD_NAME) etc.
Candidate Key
The minimal set of attribute which can uniquely identify a tuple
is known as candidate key.
For Example, STUD_NO in STUDENT relation.
There can be more than one candidate key in a relation.
For Example, STUD_NO as well as STUD_PHONE both are
candidate keys for relation STUDENT.
Primary Key
There can be more than one candidate key in a relation out of
which one can be chosen as primary key.
For Example, STUD_NO , STUD_PHONE - candidate keys for
relation STUDENT
STUD_NO - primary key (only one out of many candidate keys).
Alternate Key
The candidate key other than primary key is called as alternate
key.
For Example, STUD_NO , STUD_PHONE - candidate keys for
relation STUDENT
STUD_NO - primary key and STUD_PHONE - alternate key
Foreign Key
If an attribute can only take the values which are
present as values of some other attribute, it will
be foreign key to the attribute to which it refers.
For Example,
STUD_NO in STUDENT_COURSE is a foreign key to
STUD_NO in STUDENT relation.
What is Relational Algebra?
• Relational algebra is a widely used procedural
query language.
• It collects instances of relations as input and
gives occurrences of relations as output.
• It uses operators to perform queries. An
operator can be either unary or binary.
• It uses various operation to perform this action.
The fundamental operations of relational
algebra
Select
Project
Union
Set different
Cartesian product
Rename
• The SELECT operation is used for selecting a subset of the tuples
according to a given selection condition.
• Sigma(σ) Symbol denotes it.
• It is used as an expression to choose tuples which meet the
selection condition.
Select operation selects tuples that satisfy a given predicate.
σp
(r)
σ is the predicate
R stands for relation which is the name of the table
p is prepositional logic
SELECT (σ)
ROLL_NO SPORTS
1 Badminton
2 Cricket
2 Badminton
4 Badminton
EMP_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 9455123451 18
5 NARESH HISAR 9782918192 22
6 SWETA RANCHI 9852617621 21
4 SURESH DELHI 9156768971 18
Table 1 : EMPLOYEE
Table 2 : STUDENT_SPORTS
ROLL_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 9455123451 18
2 RAMESH GURGAON 9652431543 18
3 SUJIT ROHTAK 9156253131 20
4 SURESH DELHI 9156768971 18
Table 3 : STUDENT
ROLL_NO NAME ADDRESS PHONE AGE
3 SUJIT ROHTAK 9156253131 20
Eg:
σ (AGE>18)(STUDENT)
RESULT:
ROLL_NO NAME
1 RAM
2 RAMESH
3 SUJIT
4 SURESH
Projection Operator (∏)
Projection operator is used to project particular columns from a
relation.
SYNTAX:
∏(Column 1,Column 2….Column n)(Relation Name)
EG:
∏(ROLL_NO,NAME)(STUDENT)
RESULT
Cross Product(X)
Cross product is used to join two relations.
For every row of Relation1, each row of
Relation2 is concatenated.
Syntax: Relation1 X Relation2
Eg: STUDENT X STUDENT_SPORTS
ROLL_NO NAME ADDRESS PHONE AGE ROLL_NO SPORTS
1 RAM DELHI 9455123451 18 1 Badminton
1 RAM DELHI 9455123451 18 2 Cricket
1 RAM DELHI 9455123451 18 2 Badminton
1 RAM DELHI 9455123451 18 4 Badminton
2 RAMESH GURGAON 9652431543 18 1 Badminton
2 RAMESH GURGAON 9652431543 18 2 Cricket
2 RAMESH GURGAON 9652431543 18 2 Badminton
2 RAMESH GURGAON 9652431543 18 4 Badminton
3 SUJIT ROHTAK 9156253131 20 1 Badminton
3 SUJIT ROHTAK 9156253131 20 2 Cricket
3 SUJIT ROHTAK 9156253131 20 2 Badminton
3 SUJIT ROHTAK 9156253131 20 4 Badminton
4 SURESH DELHI 9156768971 18 1 Badminton
4 SURESH DELHI 9156768971 18 2 Cricket
4 SURESH DELHI 9156768971 18 2 Badminton
4 SURESH DELHI 9156768971 18 4 Badminton
Union (U)
Union on two relations R1 and R2 can only be computed.
Union operator when applied on two relations R1 and R2 will
give a relation with tuples which are either in R1 or in R2
Syntax: Relation1 U Relation2
Eg: STUDENT U EMPLOYEE
ROLL_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 9455123451 18
2 RAMESH GURGAON 9652431543 18
3 SUJIT ROHTAK 9156253131 20
4 SURESH DELHI 9156768971 18
5 NARESH HISAR 9782918192 22
6 SWETA RANCHI 9852617621 21
RESULT:
Minus (-)
Minus on two relations R1 and R2 can only be computed if R1
and R2 are union compatible.
Minus operator when applied on two relations as R1-R2 will
give a relation with tuples which are in R1 but not in R2.
Syntax: Relation1 - Relation2
Eg: STUDENT - EMPLOYEE
ROLL_NO NAME ADDRESS PHONE AGE
2 RAMESH GURGAON 9652431543 18
3 SUJIT ROHTAK 9156253131 20
RESULT
Rename(ρ)
Rename operator is used to give another name to a
relation.
Syntax:
ρ(Relation2, Relation1)
Eg:
ρ(STUDENT1, STUDENT)
ρ(STUDENT_NAMES, ∏(ROLL_NO, NAME)(STUDENT))
JOIN OPERATIONS
A Join operation combines related tuples from different relations, if
and only if a given join condition is satisfied.
It is denoted by ⋈
Example:
EMP_CODE EMP_NAME
101 Stephan
102 Jack
103 Harry
EMPLOYEE
EMP_CODE SALARY
101 50000
102 30000
103 25000
SALARY
Operation:
(EMPLOYEE ⋈ SALARY)
EMP_CODE EMP_NAME SALARY
101 Stephan 50000
102 Jack 30000
103 Harry 25000
Result
Relational model
EMP_NAME SALARY
Stephan 50000
Jack 30000
Harry 25000
•A natural join is the set of tuples of all combinations in
R and S that are equal on their common attribute
names.
•It is denoted by ⋈.
Example:
∏ EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)
Output:
NATURAL JOIN
EMP_
NAME
STREET CITY
Ram Civil line Mumbai
Shyam Park street Kolkata
Ravi M.G. Street Delhi
Hari Nehru nagar Hyderabad
EMP_
NAME
BRANCH SALARY
Ram Infosys 10000
Shyam Wipro 20000
Kuber HCL 30000
Hari TCS 50000
The outer join operation is an extension of the join
operation. It is used to deal with missing information.
Example
OUTER JOIN
FACT_WORKERSEMPLOYEE
EMP_NAME STREET CITY BRANCH SALARY
Ram Civil line Mumbai Infosys 10000
Shyam Park street Kolkata Wipro 20000
Hari Nehru
nagar
Hyderabad TCS 50000
(EMPLOYEE ⋈ FACT_WORKERS)
Output
EMP_NAME STREET CITY BRANCH SALARY
Ram Civil line Mumbai Infosys 10000
Shyam Park street Kolkata Wipro 20000
Hari Nehru street Hyderabad TCS 50000
Ravi M.G. Street Delhi NULL NULL
•Left outer join contains the set of tuples of all
combinations in R and S that are equal on their common
attribute names.
•In the left outer join, tuples in R have no matching
tuples in S.
•It is denoted by ⟕.
Example
EMPLOYEE ⟕ FACT_WORKERS
LEFT OUTER JOIN
EMP_NAME BRANCH SALARY STREET CITY
Ram Infosys 10000 Civil line Mumbai
Shyam Wipro 20000 Park street Kolkata
Hari TCS 50000 Nehru street Hyderabad
Kuber HCL 30000 NULL NULL
• Right outer join contains the set of tuples of all
combinations in R and S that are equal on their
common attribute names.
• In right outer join, tuples in S have no matching
tuples in R.
• It is denoted by ⟖.
Example:
EMPLOYEE ⟖ FACT_WORKERS
Output:
RIGHT OUTER JOIN
EMP_NAME STREET CITY BRANCH SALARY
Ram Civil line Mumbai Infosys 10000
Shyam Park street Kolkata Wipro 20000
Hari Nehru street Hyderabad TCS 50000
Ravi M.G. Street Delhi NULL NULL
Kuber NULL NULL HCL 30000
:Full outer join is like a left or right join except that it contains all
rows from both tables.
•In full outer join, tuples in R that have no matching tuples in S
and tuples in S that have no matching tuples in R in their
common attribute name.
•It is denoted by ⟗.
Example
EMPLOYEE ⟗ FACT_WORKERS
Output:
FULL OUTER JOIN
CLASS_ID NAME
1 John
2 Harry
3 Jackson
PRODUCT_ID CITY
1 Delhi
2 Mumbai
3 Noida
CLASS_ID NAME PRODUCT_I
D
CITY
1 John 1 Delhi
2 Harry 2 Mumbai
3 Harry 3 Noida
It is also known as an inner join. It is based on matched data as per the
equality condition. The equi join uses the comparison operator(=).
Example
CUSTOMER ⋈ PRODUCT
Output
EQUI JOIN
CUSTOMER PRODUCT
Relational algebra operations have been
extended in various ways
¤ More generalized
¤ More useful!
¨ Three major extensions:
¤ Generalized projection
¤ Aggregate functions
¤ Additional join operations
GENERALIZED PROJECTION
Written as:
∏F1, F2, …, Fn (E)
¤ Fi are arithmetic expressions
¤ E is an expression that produces a relation
¤ Derived attributes - Values are always
computed from other attributes stored in
database
¤ Also useful for updating values in database
GENERALIZED PROJECTION EXAMPLE
∏cred_id, (limit – balance) as available_credit (credit_acct)
cred_id limit balance
C-273 2500 150
C-291 750 600
C-304 15000 3500
C-313 300 25
cred_id Available_credit
C-273 2350
C-291 150
C-304 11500
C-313 275
credit_acct
available_acc
AGGREGATE FUNCTIONS
sum - sums the values in the collection
avg - computes average of values in the collection count
- counts number of elements in the collection min -
returns minimum value in the collection
Max - returns maximum value in the collection
Gsum(balance)(credit_acct)
4275
cred_id limit balance
C-273 2500 150
C-291 750 600
C-304 15000 3500
C-313 300 25
Gavg(limit)(credit_acct)
11500
Gcount(bal)(credit_acct)
4
GROUP BY FUNCTION
Relational model
and: (true and unknown) = unknown;
(false and unknown) = false;
(unknown and unknown) = unknown.
or: (true or unknown) = true;
(false or unknown) = unknown;
(unknown or un- known) = unknown.
not: (not unknown) = unknown
NULL VALUES
Null indicates - “value unknown or nonexistent,”
any arithmetic operations (such as +, −, ∗, /) involving
null values must return a null result.
MODIFICATION OF THE DATABASE
Often need to modify data in a database
Can use assignment operator 
Operations:
r  r U E Insert new tuples into a relation
r  r – E Delete tuples from a relation
r  P(r) Update tuples already in the relation
THANK YOU

More Related Content

PPTX
Recognize Relation-Function Part 1 edmodo
shumwayc
 
PPTX
2.1.1 functions and their graphs
Northside ISD
 
PDF
5 the relational algebra and calculus
Kumar
 
PPT
L1 functions, domain & range
James Tagara
 
PPT
Relational algebra.pptx
RUpaliLohar
 
PPTX
Fd & Normalization - Database Management System
Drishti Bhalla
 
PPTX
M2 l1 relations functions
RDemolina
 
PPTX
Relational Algebra Introduction
Md. Afif Al Mamun
 
Recognize Relation-Function Part 1 edmodo
shumwayc
 
2.1.1 functions and their graphs
Northside ISD
 
5 the relational algebra and calculus
Kumar
 
L1 functions, domain & range
James Tagara
 
Relational algebra.pptx
RUpaliLohar
 
Fd & Normalization - Database Management System
Drishti Bhalla
 
M2 l1 relations functions
RDemolina
 
Relational Algebra Introduction
Md. Afif Al Mamun
 

What's hot (20)

PPT
8.1 Relations And Functions
Jessca Lundin
 
PPT
Relations and functions remediation notes
carolinevest77
 
PPT
Relational Algebra-Database Systems
jakodongo
 
PPTX
Relational algebra (basics)
usama nizam
 
PPT
My slide relational algebra
Rushdi Shams
 
PPTX
Math functions, relations, domain & range
Renee Scott
 
PDF
Relational Algebra & Calculus
Abdullah Khosa
 
PPTX
Relations and functions
Vishwakarma Nutan Prakash
 
PDF
Relations and functions
Rhea Rose Almoguez
 
PPTX
Decomposition using Functional Dependency
Raj Naik
 
PPT
Relations & functions
chrystal_brinson
 
PPT
Functions domain-range
Olaug S
 
PPT
4.6 Relations And Functions
guestd1dc2e
 
PPTX
Normal forms
Samuel Igbanogu
 
PPTX
Normalization 1 nf,2nf,3nf,bcnf
Shriya agrawal
 
PPTX
Alg2 lesson 2.1
Carol Defreese
 
PDF
Additional Relational Algebra Operations
A. S. M. Shafi
 
PPTX
8.1 intro to functions
Barbara Knab
 
PPT
functional dependencies with example
Siddhi Viradiya
 
8.1 Relations And Functions
Jessca Lundin
 
Relations and functions remediation notes
carolinevest77
 
Relational Algebra-Database Systems
jakodongo
 
Relational algebra (basics)
usama nizam
 
My slide relational algebra
Rushdi Shams
 
Math functions, relations, domain & range
Renee Scott
 
Relational Algebra & Calculus
Abdullah Khosa
 
Relations and functions
Vishwakarma Nutan Prakash
 
Relations and functions
Rhea Rose Almoguez
 
Decomposition using Functional Dependency
Raj Naik
 
Relations & functions
chrystal_brinson
 
Functions domain-range
Olaug S
 
4.6 Relations And Functions
guestd1dc2e
 
Normal forms
Samuel Igbanogu
 
Normalization 1 nf,2nf,3nf,bcnf
Shriya agrawal
 
Alg2 lesson 2.1
Carol Defreese
 
Additional Relational Algebra Operations
A. S. M. Shafi
 
8.1 intro to functions
Barbara Knab
 
functional dependencies with example
Siddhi Viradiya
 
Ad

Similar to Relational model (20)

PPT
Unit2 -DBMS.ppt with type of job operation
shindhe1098cv
 
PPT
Unit04 dbms
arnold 7490
 
PPTX
Dbms relational model
Radhika Talaviya
 
PPTX
Relational algebr
Visakh V
 
PDF
1695304562_RELATIONAL_ALGEBRA.pdf
Kavinilaa
 
PPTX
DBMS - Relational Model, Relational Table
ahirevedant07
 
DOCX
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Raj vardhan
 
PDF
3_Relational_Model.pdf
SrikanthS494888
 
PDF
4 the sql_standard
Utkarsh De
 
PPTX
Dbms unit ii
Arnav Chowdhury
 
PPT
sql statement
zx25 zx25
 
PDF
3 relational model
Utkarsh De
 
PPTX
Types of keys
Bhavana sharma
 
PDF
SQL- MOST IMPORTANT CONCEPTS
Gagandeep Nanda
 
PPTX
Statements,joins and operators in sql by thanveer danish melayi(1)
Muhammed Thanveer M
 
PPTX
SQL Operators.pptx
RUBAB79
 
PPTX
Relational Database management Systems unit-II
vanithar32
 
PDF
SQL Joins - Oracle SQL Fundamentals
MuhammadWaheed44
 
PPT
relational algebra and it's implementation
dbmscse61
 
Unit2 -DBMS.ppt with type of job operation
shindhe1098cv
 
Unit04 dbms
arnold 7490
 
Dbms relational model
Radhika Talaviya
 
Relational algebr
Visakh V
 
1695304562_RELATIONAL_ALGEBRA.pdf
Kavinilaa
 
DBMS - Relational Model, Relational Table
ahirevedant07
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Raj vardhan
 
3_Relational_Model.pdf
SrikanthS494888
 
4 the sql_standard
Utkarsh De
 
Dbms unit ii
Arnav Chowdhury
 
sql statement
zx25 zx25
 
3 relational model
Utkarsh De
 
Types of keys
Bhavana sharma
 
SQL- MOST IMPORTANT CONCEPTS
Gagandeep Nanda
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Muhammed Thanveer M
 
SQL Operators.pptx
RUBAB79
 
Relational Database management Systems unit-II
vanithar32
 
SQL Joins - Oracle SQL Fundamentals
MuhammadWaheed44
 
relational algebra and it's implementation
dbmscse61
 
Ad

Recently uploaded (20)

PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Virus sequence retrieval from NCBI database
yamunaK13
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 

Relational model

  • 1. DATABASE SYSTEMS STAFF NAME : D.SARITHA ASSISTANT PROFESSOR DEPARTMENT OF COMPUTER APPLICATIONS BON SECOURS COLLEGE FOR WOMEN THANJAVUR UNIT : II CHAPTER : 2 TOPIC : RELATIONAL MODEL
  • 3. ROLL_NO NAME ADDRESS PHONE AGE 1 RAM DELHI 9455123451 18 2 RAMESH GURGAON 9652431543 18 3 SUJIT ROHTAK 9156253131 20 4 SURESH DELHI 18 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). Consider a relation STUDENT with attributes ROLL_NO, NAME, ADDRESS, PHONE and AGE shown in Table STUDENT
  • 4. 1 RAM DELHI 9455123451 18 IMPORTANT TERMINOLOGIES 1.Attribute: Attributes are the properties that define a relation. e.g.; ROLL_NO, NAME 2.Relation Schema: A relation schema represents name of the relation with its attributes. e.g.; STUDENT (ROLL_NO, NAME, ADDRESS, PHONE and AGE) is relation schema for STUDENT. If a schema has more than 1 relation, it is called Relational Schema. 3.Tuple: Each row in the relation is known as tuple. The above relation contains 4 tuples, one of which is shown as: 4.Relation Instance: The set of tuples of a relation at a particular instance of time is called as relation instance.
  • 5. ROLL_NO 1 2 3 4 5.Degree: The number of attributes in the relation is known as degree of the relation. The STUDENT relation defined above has degree 5. 6.Cardinality: The number of tuples in a relation is known as cardinality. The STUDENT relation defined above has cardinality 4. 7.Column: Column represents the set of values for a particular attribute. The column ROLL_NO is extracted from relation STUDENT. 8.NULL Values: The value which is not known or unavailable is called NULL value. It is represented by blank space. e.g.; PHONE of STUDENT having ROLL_NO 4 is NULL.
  • 6. Different Types of Keys in Relational Model
  • 7. Super Key The set of attributes which can uniquely identify a tuple is known as Super Key. For Example, STUD_NO, (STUD_NO, STUD_NAME) etc. Candidate Key The minimal set of attribute which can uniquely identify a tuple is known as candidate key. For Example, STUD_NO in STUDENT relation. There can be more than one candidate key in a relation. For Example, STUD_NO as well as STUD_PHONE both are candidate keys for relation STUDENT.
  • 8. Primary Key There can be more than one candidate key in a relation out of which one can be chosen as primary key. For Example, STUD_NO , STUD_PHONE - candidate keys for relation STUDENT STUD_NO - primary key (only one out of many candidate keys). Alternate Key The candidate key other than primary key is called as alternate key. For Example, STUD_NO , STUD_PHONE - candidate keys for relation STUDENT STUD_NO - primary key and STUD_PHONE - alternate key
  • 9. Foreign Key If an attribute can only take the values which are present as values of some other attribute, it will be foreign key to the attribute to which it refers. For Example, STUD_NO in STUDENT_COURSE is a foreign key to STUD_NO in STUDENT relation.
  • 10. What is Relational Algebra? • Relational algebra is a widely used procedural query language. • It collects instances of relations as input and gives occurrences of relations as output. • It uses operators to perform queries. An operator can be either unary or binary. • It uses various operation to perform this action.
  • 11. The fundamental operations of relational algebra Select Project Union Set different Cartesian product Rename
  • 12. • The SELECT operation is used for selecting a subset of the tuples according to a given selection condition. • Sigma(σ) Symbol denotes it. • It is used as an expression to choose tuples which meet the selection condition. Select operation selects tuples that satisfy a given predicate. σp (r) σ is the predicate R stands for relation which is the name of the table p is prepositional logic SELECT (σ)
  • 13. ROLL_NO SPORTS 1 Badminton 2 Cricket 2 Badminton 4 Badminton EMP_NO NAME ADDRESS PHONE AGE 1 RAM DELHI 9455123451 18 5 NARESH HISAR 9782918192 22 6 SWETA RANCHI 9852617621 21 4 SURESH DELHI 9156768971 18 Table 1 : EMPLOYEE Table 2 : STUDENT_SPORTS
  • 14. ROLL_NO NAME ADDRESS PHONE AGE 1 RAM DELHI 9455123451 18 2 RAMESH GURGAON 9652431543 18 3 SUJIT ROHTAK 9156253131 20 4 SURESH DELHI 9156768971 18 Table 3 : STUDENT
  • 15. ROLL_NO NAME ADDRESS PHONE AGE 3 SUJIT ROHTAK 9156253131 20 Eg: σ (AGE>18)(STUDENT) RESULT:
  • 16. ROLL_NO NAME 1 RAM 2 RAMESH 3 SUJIT 4 SURESH Projection Operator (∏) Projection operator is used to project particular columns from a relation. SYNTAX: ∏(Column 1,Column 2….Column n)(Relation Name) EG: ∏(ROLL_NO,NAME)(STUDENT) RESULT
  • 17. Cross Product(X) Cross product is used to join two relations. For every row of Relation1, each row of Relation2 is concatenated. Syntax: Relation1 X Relation2 Eg: STUDENT X STUDENT_SPORTS
  • 18. ROLL_NO NAME ADDRESS PHONE AGE ROLL_NO SPORTS 1 RAM DELHI 9455123451 18 1 Badminton 1 RAM DELHI 9455123451 18 2 Cricket 1 RAM DELHI 9455123451 18 2 Badminton 1 RAM DELHI 9455123451 18 4 Badminton 2 RAMESH GURGAON 9652431543 18 1 Badminton 2 RAMESH GURGAON 9652431543 18 2 Cricket 2 RAMESH GURGAON 9652431543 18 2 Badminton 2 RAMESH GURGAON 9652431543 18 4 Badminton 3 SUJIT ROHTAK 9156253131 20 1 Badminton 3 SUJIT ROHTAK 9156253131 20 2 Cricket 3 SUJIT ROHTAK 9156253131 20 2 Badminton 3 SUJIT ROHTAK 9156253131 20 4 Badminton 4 SURESH DELHI 9156768971 18 1 Badminton 4 SURESH DELHI 9156768971 18 2 Cricket 4 SURESH DELHI 9156768971 18 2 Badminton 4 SURESH DELHI 9156768971 18 4 Badminton
  • 19. Union (U) Union on two relations R1 and R2 can only be computed. Union operator when applied on two relations R1 and R2 will give a relation with tuples which are either in R1 or in R2 Syntax: Relation1 U Relation2 Eg: STUDENT U EMPLOYEE ROLL_NO NAME ADDRESS PHONE AGE 1 RAM DELHI 9455123451 18 2 RAMESH GURGAON 9652431543 18 3 SUJIT ROHTAK 9156253131 20 4 SURESH DELHI 9156768971 18 5 NARESH HISAR 9782918192 22 6 SWETA RANCHI 9852617621 21 RESULT:
  • 20. Minus (-) Minus on two relations R1 and R2 can only be computed if R1 and R2 are union compatible. Minus operator when applied on two relations as R1-R2 will give a relation with tuples which are in R1 but not in R2. Syntax: Relation1 - Relation2 Eg: STUDENT - EMPLOYEE ROLL_NO NAME ADDRESS PHONE AGE 2 RAMESH GURGAON 9652431543 18 3 SUJIT ROHTAK 9156253131 20 RESULT
  • 21. Rename(ρ) Rename operator is used to give another name to a relation. Syntax: ρ(Relation2, Relation1) Eg: ρ(STUDENT1, STUDENT) ρ(STUDENT_NAMES, ∏(ROLL_NO, NAME)(STUDENT))
  • 22. JOIN OPERATIONS A Join operation combines related tuples from different relations, if and only if a given join condition is satisfied. It is denoted by ⋈ Example: EMP_CODE EMP_NAME 101 Stephan 102 Jack 103 Harry EMPLOYEE EMP_CODE SALARY 101 50000 102 30000 103 25000 SALARY Operation: (EMPLOYEE ⋈ SALARY)
  • 23. EMP_CODE EMP_NAME SALARY 101 Stephan 50000 102 Jack 30000 103 Harry 25000 Result
  • 25. EMP_NAME SALARY Stephan 50000 Jack 30000 Harry 25000 •A natural join is the set of tuples of all combinations in R and S that are equal on their common attribute names. •It is denoted by ⋈. Example: ∏ EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY) Output: NATURAL JOIN
  • 26. EMP_ NAME STREET CITY Ram Civil line Mumbai Shyam Park street Kolkata Ravi M.G. Street Delhi Hari Nehru nagar Hyderabad EMP_ NAME BRANCH SALARY Ram Infosys 10000 Shyam Wipro 20000 Kuber HCL 30000 Hari TCS 50000 The outer join operation is an extension of the join operation. It is used to deal with missing information. Example OUTER JOIN FACT_WORKERSEMPLOYEE
  • 27. EMP_NAME STREET CITY BRANCH SALARY Ram Civil line Mumbai Infosys 10000 Shyam Park street Kolkata Wipro 20000 Hari Nehru nagar Hyderabad TCS 50000 (EMPLOYEE ⋈ FACT_WORKERS) Output
  • 28. EMP_NAME STREET CITY BRANCH SALARY Ram Civil line Mumbai Infosys 10000 Shyam Park street Kolkata Wipro 20000 Hari Nehru street Hyderabad TCS 50000 Ravi M.G. Street Delhi NULL NULL •Left outer join contains the set of tuples of all combinations in R and S that are equal on their common attribute names. •In the left outer join, tuples in R have no matching tuples in S. •It is denoted by ⟕. Example EMPLOYEE ⟕ FACT_WORKERS LEFT OUTER JOIN
  • 29. EMP_NAME BRANCH SALARY STREET CITY Ram Infosys 10000 Civil line Mumbai Shyam Wipro 20000 Park street Kolkata Hari TCS 50000 Nehru street Hyderabad Kuber HCL 30000 NULL NULL • Right outer join contains the set of tuples of all combinations in R and S that are equal on their common attribute names. • In right outer join, tuples in S have no matching tuples in R. • It is denoted by ⟖. Example: EMPLOYEE ⟖ FACT_WORKERS Output: RIGHT OUTER JOIN
  • 30. EMP_NAME STREET CITY BRANCH SALARY Ram Civil line Mumbai Infosys 10000 Shyam Park street Kolkata Wipro 20000 Hari Nehru street Hyderabad TCS 50000 Ravi M.G. Street Delhi NULL NULL Kuber NULL NULL HCL 30000 :Full outer join is like a left or right join except that it contains all rows from both tables. •In full outer join, tuples in R that have no matching tuples in S and tuples in S that have no matching tuples in R in their common attribute name. •It is denoted by ⟗. Example EMPLOYEE ⟗ FACT_WORKERS Output: FULL OUTER JOIN
  • 31. CLASS_ID NAME 1 John 2 Harry 3 Jackson PRODUCT_ID CITY 1 Delhi 2 Mumbai 3 Noida CLASS_ID NAME PRODUCT_I D CITY 1 John 1 Delhi 2 Harry 2 Mumbai 3 Harry 3 Noida It is also known as an inner join. It is based on matched data as per the equality condition. The equi join uses the comparison operator(=). Example CUSTOMER ⋈ PRODUCT Output EQUI JOIN CUSTOMER PRODUCT
  • 32. Relational algebra operations have been extended in various ways ¤ More generalized ¤ More useful! ¨ Three major extensions: ¤ Generalized projection ¤ Aggregate functions ¤ Additional join operations
  • 33. GENERALIZED PROJECTION Written as: ∏F1, F2, …, Fn (E) ¤ Fi are arithmetic expressions ¤ E is an expression that produces a relation ¤ Derived attributes - Values are always computed from other attributes stored in database ¤ Also useful for updating values in database
  • 34. GENERALIZED PROJECTION EXAMPLE ∏cred_id, (limit – balance) as available_credit (credit_acct) cred_id limit balance C-273 2500 150 C-291 750 600 C-304 15000 3500 C-313 300 25 cred_id Available_credit C-273 2350 C-291 150 C-304 11500 C-313 275 credit_acct available_acc
  • 35. AGGREGATE FUNCTIONS sum - sums the values in the collection avg - computes average of values in the collection count - counts number of elements in the collection min - returns minimum value in the collection Max - returns maximum value in the collection
  • 36. Gsum(balance)(credit_acct) 4275 cred_id limit balance C-273 2500 150 C-291 750 600 C-304 15000 3500 C-313 300 25 Gavg(limit)(credit_acct) 11500 Gcount(bal)(credit_acct) 4
  • 39. and: (true and unknown) = unknown; (false and unknown) = false; (unknown and unknown) = unknown. or: (true or unknown) = true; (false or unknown) = unknown; (unknown or un- known) = unknown. not: (not unknown) = unknown NULL VALUES Null indicates - “value unknown or nonexistent,” any arithmetic operations (such as +, −, ∗, /) involving null values must return a null result.
  • 40. MODIFICATION OF THE DATABASE Often need to modify data in a database Can use assignment operator  Operations: r  r U E Insert new tuples into a relation r  r – E Delete tuples from a relation r  P(r) Update tuples already in the relation