SlideShare a Scribd company logo
1 of 41
Download to read offline
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
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
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

What's hot

8.1 Relations And Functions
8.1 Relations And Functions8.1 Relations And Functions
8.1 Relations And FunctionsJessca Lundin
 
Relations and functions remediation notes
Relations and functions remediation notesRelations and functions remediation notes
Relations and functions remediation notescarolinevest77
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systemsjakodongo
 
Relational algebra (basics)
Relational algebra (basics)Relational algebra (basics)
Relational algebra (basics)usama nizam
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebraRushdi Shams
 
Math functions, relations, domain & range
Math functions, relations, domain & rangeMath functions, relations, domain & range
Math functions, relations, domain & rangeRenee Scott
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & CalculusAbdullah Khosa
 
Decomposition using Functional Dependency
Decomposition using Functional DependencyDecomposition using Functional Dependency
Decomposition using Functional DependencyRaj Naik
 
Functions domain-range
Functions domain-rangeFunctions domain-range
Functions domain-rangeOlaug S
 
4.6 Relations And Functions
4.6 Relations And Functions4.6 Relations And Functions
4.6 Relations And Functionsguestd1dc2e
 
Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf Shriya agrawal
 
Additional Relational Algebra Operations
Additional Relational Algebra OperationsAdditional Relational Algebra Operations
Additional Relational Algebra OperationsA. S. M. Shafi
 
8.1 intro to functions
8.1 intro to functions8.1 intro to functions
8.1 intro to functionsBarbara Knab
 
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with exampleSiddhi Viradiya
 

What's hot (20)

8.1 Relations And Functions
8.1 Relations And Functions8.1 Relations And Functions
8.1 Relations And Functions
 
Relations and functions remediation notes
Relations and functions remediation notesRelations and functions remediation notes
Relations and functions remediation notes
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
 
Relational algebra (basics)
Relational algebra (basics)Relational algebra (basics)
Relational algebra (basics)
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
 
Math functions, relations, domain & range
Math functions, relations, domain & rangeMath functions, relations, domain & range
Math functions, relations, domain & range
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 
Relations and functions
Relations and functionsRelations and functions
Relations and functions
 
Relations and functions
Relations and functionsRelations and functions
Relations and functions
 
Decomposition using Functional Dependency
Decomposition using Functional DependencyDecomposition using Functional Dependency
Decomposition using Functional Dependency
 
Relations & functions
Relations & functionsRelations & functions
Relations & functions
 
Functions domain-range
Functions domain-rangeFunctions domain-range
Functions domain-range
 
4.6 Relations And Functions
4.6 Relations And Functions4.6 Relations And Functions
4.6 Relations And Functions
 
Normal forms
Normal formsNormal forms
Normal forms
 
Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf
 
Alg2 lesson 2.1
Alg2 lesson 2.1Alg2 lesson 2.1
Alg2 lesson 2.1
 
Additional Relational Algebra Operations
Additional Relational Algebra OperationsAdditional Relational Algebra Operations
Additional Relational Algebra Operations
 
8.1 intro to functions
8.1 intro to functions8.1 intro to functions
8.1 intro to functions
 
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with example
 
Normalization
NormalizationNormalization
Normalization
 

Similar to Relational model

Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationshindhe1098cv
 
Relational algebr
Relational algebrRelational algebr
Relational algebrVisakh V
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdfKavinilaa
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Raj vardhan
 
Module 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxModule 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxShashiKumarB5
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standardUtkarsh De
 
sql statement
sql statementsql statement
sql statementzx25 zx25
 
3 relational model
3 relational model3 relational model
3 relational modelUtkarsh De
 
SQL- MOST IMPORTANT CONCEPTS
SQL- MOST IMPORTANT CONCEPTSSQL- MOST IMPORTANT CONCEPTS
SQL- MOST IMPORTANT CONCEPTSGagandeep Nanda
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Muhammed Thanveer M
 
SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptxRUBAB79
 
SQL Joins - Oracle SQL Fundamentals
SQL Joins - Oracle SQL FundamentalsSQL Joins - Oracle SQL Fundamentals
SQL Joins - Oracle SQL FundamentalsMuhammadWaheed44
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 

Similar to Relational model (20)

Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operation
 
Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Relational algebr
Relational algebrRelational algebr
Relational algebr
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
 
Module 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxModule 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptx
 
NMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.pptNMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.ppt
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standard
 
Dbms unit ii
Dbms unit iiDbms unit ii
Dbms unit ii
 
sql statement
sql statementsql statement
sql statement
 
3 relational model
3 relational model3 relational model
3 relational model
 
Types of keys
Types of keysTypes of keys
Types of keys
 
SQL- MOST IMPORTANT CONCEPTS
SQL- MOST IMPORTANT CONCEPTSSQL- MOST IMPORTANT CONCEPTS
SQL- MOST IMPORTANT CONCEPTS
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)
 
SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptx
 
SQL Joins - Oracle SQL Fundamentals
SQL Joins - Oracle SQL FundamentalsSQL Joins - Oracle SQL Fundamentals
SQL Joins - Oracle SQL Fundamentals
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 

Recently uploaded

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

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
  • 24.
  • 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
  • 38.
  • 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