SlideShare a Scribd company logo
Database System Concepts, 7th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Chapter 2: Intro to Relational Model
©Silberschatz, Korth and Sudarshan
2.2
Database System Concepts - 7th Edition
Outline
 Structure of Relational Databases
 Database Schema
 Keys
 Schema Diagrams
 Relational Query Languages
 The Relational Algebra
©Silberschatz, Korth and Sudarshan
2.3
Database System Concepts - 7th Edition
Example of a Instructor Relation
attributes
(or columns)
tuples
(or rows)
©Silberschatz, Korth and Sudarshan
2.4
Database System Concepts - 7th Edition
Relation Schema and Instance
 A1, A2, …, An are attributes
 R = (A1, A2, …, An ) is a relation schema
Example:
instructor = (ID, name, dept_name, salary)
 A relation instance r defined over schema R is denoted by r (R).
 The current values a relation are specified by a table
 An element t of relation r is called a tuple and is represented by
a row in a table
©Silberschatz, Korth and Sudarshan
2.5
Database System Concepts - 7th Edition
Attributes
 The set of allowed values for each attribute is called the domain of the
attribute
 Attribute values are (normally) required to be atomic; that is, indivisible
 The special value null is a member of every domain. Indicated that the
value is “unknown”
 The null value causes complications in the definition of many operations
©Silberschatz, Korth and Sudarshan
2.6
Database System Concepts - 7th Edition
Relations are Unordered
 Order of tuples is irrelevant (tuples may be stored in an arbitrary order)
 Example: instructor relation with unordered tuples
©Silberschatz, Korth and Sudarshan
2.7
Database System Concepts - 7th Edition
Database Schema
 Database schema -- is the logical structure of the database.
 Database instance -- is a snapshot of the data in the database at a given
instant in time.
 Example:
• schema: instructor (ID, name, dept_name, salary)
• Instance:
©Silberschatz, Korth and Sudarshan
2.8
Database System Concepts - 7th Edition
Keys
 Let K  R
 K is a superkey of R if values for K are sufficient to identify a unique tuple
of each possible relation r(R)
• Example: {ID} and {ID,name} are both superkeys of instructor.
 Superkey K is a candidate key if K is minimal
Example: {ID} is a candidate key for Instructor
 One of the candidate keys is selected to be the primary key.
• Which one?
 Foreign key constraint: Value in one relation must appear in another
• Referencing relation
• Referenced relation
• Example: dept_name in instructor is a foreign key from instructor
referencing department
©Silberschatz, Korth and Sudarshan
2.9
Database System Concepts - 7th Edition
Schema Diagram for University Database
©Silberschatz, Korth and Sudarshan
2.10
Database System Concepts - 7th Edition
Relational Query Languages
 Procedural versus non-procedural, or declarative
 “Pure” languages:
• Relational algebra
• Tuple relational calculus
• Domain relational calculus
 The above 3 pure languages are equivalent in computing power
 We will concentrate in this chapter on relational algebra
• Not Turing-machine equivalent
• Consists of 6 basic operations
©Silberschatz, Korth and Sudarshan
2.11
Database System Concepts - 7th Edition
Relational Algebra
 A procedural language consisting of a set of operations that take one or
two relations as input and produce a new relation as their result.
 Six basic operators
• select: 
• project: 
• union: 
• set difference: –
• Cartesian product: x
• rename: 
©Silberschatz, Korth and Sudarshan
2.12
Database System Concepts - 7th Edition
Select Operation
 The select operation selects tuples that satisfy a given predicate.
 Notation:  p (r)
 p is called the selection predicate
 Example: select those tuples of the instructor relation where the
instructor is in the “Physics” department.
• Query
 dept_name=“Physics” (instructor)
• Result
©Silberschatz, Korth and Sudarshan
2.13
Database System Concepts - 7th Edition
Select Operation (Cont.)
 We allow comparisons using
=, , >, . <. 
in the selection predicate.
 We can combine several predicates into a larger predicate by using the
connectives:
 (and),  (or),  (not)
 Example: Find the instructors in Physics with a salary greater $90,000, we
write:
 dept_name=“Physics”  salary > 90,000 (instructor)
 The select predicate may include comparisons between two attributes.
• Example, find all departments whose name is the same as their
building name:
•  dept_name=building (department)
©Silberschatz, Korth and Sudarshan
2.14
Database System Concepts - 7th Edition
Project Operation
 A unary operation that returns its argument relation, with certain attributes
left out.
 Notation:
 A1,A2,A3 ….Ak
(r)
where A1, A2, …, Ak are attribute names and r is a relation name.
 The result is defined as the relation of k columns obtained by erasing the
columns that are not listed
 Duplicate rows removed from result, since relations are sets
©Silberschatz, Korth and Sudarshan
2.15
Database System Concepts - 7th Edition
Project Operation Example
 Example: eliminate the dept_name attribute of instructor
 Query:
ID, name, salary (instructor)
 Result:
©Silberschatz, Korth and Sudarshan
2.16
Database System Concepts - 7th Edition
Composition of Relational Operations
 The result of a relational-algebra operation is relation and therefore of
relational-algebra operations can be composed together into a
relational-algebra expression.
 Consider the query -- Find the names of all instructors in the Physics
department.
name( dept_name =“Physics” (instructor))
 Instead of giving the name of a relation as the argument of the projection
operation, we give an expression that evaluates to a relation.
©Silberschatz, Korth and Sudarshan
2.17
Database System Concepts - 7th Edition
Cartesian-Product Operation
 The Cartesian-product operation (denoted by X) allows us to combine
information from any two relations.
 Example: the Cartesian product of the relations instructor and teaches is
written as:
instructor X teaches
 We construct a tuple of the result out of each possible pair of tuples: one
from the instructor relation and one from the teaches relation (see next
slide)
 Since the instructor ID appears in both relations we distinguish between
these attribute by attaching to the attribute the name of the relation from
which the attribute originally came.
• instructor.ID
• teaches.ID
©Silberschatz, Korth and Sudarshan
2.18
Database System Concepts - 7th Edition
The instructor X teaches table
©Silberschatz, Korth and Sudarshan
2.19
Database System Concepts - 7th Edition
Join Operation
 The Cartesian-Product
instructor X teaches
associates every tuple of instructor with every tuple of teaches.
• Most of the resulting rows have information about instructors who did
NOT teach a particular course.
 To get only those tuples of “instructor X teaches “ that pertain to
instructors and the courses that they taught, we write:
 instructor.id = teaches.id (instructor x teaches ))
• We get only those tuples of “instructor X teaches” that pertain to
instructors and the courses that they taught.
 The result of this expression, shown in the next slide
©Silberschatz, Korth and Sudarshan
2.20
Database System Concepts - 7th Edition
Join Operation (Cont.)
 The table corresponding to:
 instructor.id = teaches.id (instructor x teaches))
©Silberschatz, Korth and Sudarshan
2.21
Database System Concepts - 7th Edition
Join Operation (Cont.)
 The join operation allows us to combine a select operation and a
Cartesian-Product operation into a single operation.
 Consider relations r (R) and s (S)
 Let “theta” be a predicate on attributes in the schema R “union” S. The
join operation r ⋈𝜃 s is defined as follows:
𝑟 ⋈𝜃 𝑠 = 𝜎𝜃 (𝑟 × 𝑠)
 Thus
 instructor.id = teaches.id (instructor x teaches ))
 Can equivalently be written as
instructor ⋈ Instructor.id = teaches.id teaches.
©Silberschatz, Korth and Sudarshan
2.22
Database System Concepts - 7th Edition
Union Operation
 The union operation allows us to combine two relations
 Notation: r  s
 For r  s to be valid.
1. r, s must have the same arity (same number of attributes)
2. The attribute domains must be compatible (example: 2nd
column of r deals with the same type of values as does the
2nd column of s)
 Example: to find all courses taught in the Fall 2017 semester, or in the
Spring 2018 semester, or in both
course_id ( semester=“Fall” Λ year=2017 (section)) 
course_id ( semester=“Spring” Λ year=2018 (section))
©Silberschatz, Korth and Sudarshan
2.23
Database System Concepts - 7th Edition
Union Operation (Cont.)
 Result of:
course_id ( semester=“Fall” Λ year=2017 (section)) 
course_id ( semester=“Spring” Λ year=2018 (section))
©Silberschatz, Korth and Sudarshan
2.24
Database System Concepts - 7th Edition
Set-Intersection Operation
 The set-intersection operation allows us to find tuples that are in both
the input relations.
 Notation: r  s
 Assume:
• r, s have the same arity
• attributes of r and s are compatible
 Example: Find the set of all courses taught in both the Fall 2017 and the
Spring 2018 semesters.
course_id ( semester=“Fall” Λ year=2017 (section)) 
course_id ( semester=“Spring” Λ year=2018 (section))
• Result
©Silberschatz, Korth and Sudarshan
2.25
Database System Concepts - 7th Edition
Set Difference Operation
 The set-difference operation allows us to find tuples that are in one relation
but are not in another.
 Notation r – s
 Set differences must be taken between compatible relations.
• r and s must have the same arity
• attribute domains of r and s must be compatible
 Example: to find all courses taught in the Fall 2017 semester, but not in the
Spring 2018 semester
course_id ( semester=“Fall” Λ year=2017 (section)) −
course_id ( semester=“Spring” Λ year=2018 (section))
©Silberschatz, Korth and Sudarshan
2.26
Database System Concepts - 7th Edition
The Assignment Operation
 It is convenient at times to write a relational-algebra expression by
assigning parts of it to temporary relation variables.
 The assignment operation is denoted by  and works like assignment in
a programming language.
 Example: Find all instructor in the “Physics” and Music department.
Physics   dept_name=“Physics” (instructor)
Music   dept_name=“Music” (instructor)
Physics  Music
 With the assignment operation, a query can be written as a sequential
program consisting of a series of assignments followed by an expression
whose value is displayed as the result of the query.
©Silberschatz, Korth and Sudarshan
2.27
Database System Concepts - 7th Edition
The Rename Operation
 The results of relational-algebra expressions do not have a name that we
can use to refer to them. The rename operator,  , is provided for that
purpose
 The expression:
x (E)
returns the result of expression E under the name x
 Another form of the rename operation:
x(A1,A2, .. An) (E)
©Silberschatz, Korth and Sudarshan
2.28
Database System Concepts - 7th Edition
Equivalent Queries
 There is more than one way to write a query in relational algebra.
 Example: Find information about courses taught by instructors in the
Physics department with salary greater than 90,000
 Query 1
 dept_name=“Physics”  salary > 90,000 (instructor)
 Query 2
 dept_name=“Physics” ( salary > 90.000 (instructor))
 The two queries are not identical; they are, however, equivalent -- they
give the same result on any database.
©Silberschatz, Korth and Sudarshan
2.29
Database System Concepts - 7th Edition
Equivalent Queries
 There is more than one way to write a query in relational algebra.
 Example: Find information about courses taught by instructors in the
Physics department
 Query 1
dept_name=“Physics” (instructor ⋈ instructor.ID = teaches.ID teaches)
 Query 2
(dept_name=“Physics” (instructor)) ⋈ instructor.ID = teaches.ID teaches
 The two queries are not identical; they are, however, equivalent -- they
give the same result on any database.
©Silberschatz, Korth and Sudarshan
2.30
Database System Concepts - 7th Edition
End of Chapter 2

More Related Content

What's hot

Database concepts
Database conceptsDatabase concepts
Database concepts
Harry Potter
 
DBMS unit-3.pdf
DBMS unit-3.pdfDBMS unit-3.pdf
DBMS unit-3.pdf
Prof. Dr. K. Adisesha
 
Relational model
Relational modelRelational model
Relational model
Dabbal Singh Mahara
 
File organization and introduction of DBMS
File organization and introduction of DBMSFile organization and introduction of DBMS
File organization and introduction of DBMS
VrushaliSolanke
 
Rdbms
RdbmsRdbms
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
mysql content
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
Nikhil Deswal
 
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) ModelingEnhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modeling
sontumax
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
saurabhshertukde
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
Kumar
 
Database Normalization by Dr. Kamal Gulati
Database Normalization by Dr. Kamal GulatiDatabase Normalization by Dr. Kamal Gulati
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
Siti Ismail
 
DBMS.pptx
DBMS.pptxDBMS.pptx
Object oriented database model
Object oriented database modelObject oriented database model
Object oriented database model
Janecatalla
 
Normalization of database tables
Normalization of database tablesNormalization of database tables
Normalization of database tables
Dhani Ahmad
 
SQL - RDBMS Concepts
SQL - RDBMS ConceptsSQL - RDBMS Concepts
SQL - RDBMS Concepts
WebStackAcademy
 
Relational Database Fundamentals
Relational Database FundamentalsRelational Database Fundamentals
Relational Database Fundamentals
KHALID C
 
Dbms slides
Dbms slidesDbms slides
Dbms slides
rahulrathore725
 
1.2 steps and functionalities
1.2 steps and functionalities1.2 steps and functionalities
1.2 steps and functionalities
Krish_ver2
 
Dbms
DbmsDbms

What's hot (20)

Database concepts
Database conceptsDatabase concepts
Database concepts
 
DBMS unit-3.pdf
DBMS unit-3.pdfDBMS unit-3.pdf
DBMS unit-3.pdf
 
Relational model
Relational modelRelational model
Relational model
 
File organization and introduction of DBMS
File organization and introduction of DBMSFile organization and introduction of DBMS
File organization and introduction of DBMS
 
Rdbms
RdbmsRdbms
Rdbms
 
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
 
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) ModelingEnhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modeling
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
 
Database Normalization by Dr. Kamal Gulati
Database Normalization by Dr. Kamal GulatiDatabase Normalization by Dr. Kamal Gulati
Database Normalization by Dr. Kamal Gulati
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
 
Object oriented database model
Object oriented database modelObject oriented database model
Object oriented database model
 
Normalization of database tables
Normalization of database tablesNormalization of database tables
Normalization of database tables
 
SQL - RDBMS Concepts
SQL - RDBMS ConceptsSQL - RDBMS Concepts
SQL - RDBMS Concepts
 
Relational Database Fundamentals
Relational Database FundamentalsRelational Database Fundamentals
Relational Database Fundamentals
 
Dbms slides
Dbms slidesDbms slides
Dbms slides
 
1.2 steps and functionalities
1.2 steps and functionalities1.2 steps and functionalities
1.2 steps and functionalities
 
Dbms
DbmsDbms
Dbms
 

Similar to Intro to Relational Model

Relational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptRelational Algebra and relational queries .ppt
Relational Algebra and relational queries .ppt
ShahidSultan24
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
Ashwini Rao
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
rahulnadola3
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
DHAAROUN
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
poovathi nps
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
pradnyamulay
 
ch3.ppt
ch3.pptch3.ppt
Ch 3.pdf
Ch 3.pdfCh 3.pdf
DBMS _Relational model
DBMS _Relational modelDBMS _Relational model
DBMS _Relational model
Azizul Mamun
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
Shobi29
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
TanishaKochak
 
Ch 2.pdf
Ch 2.pdfCh 2.pdf
Ch6 formal relational query languages
Ch6 formal relational query languages Ch6 formal relational query languages
Ch6 formal relational query languages
uoitc
 
DBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQLDBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQL
Azizul Mamun
 
Ch3
Ch3Ch3
ch6.pptx
ch6.pptxch6.pptx
Database System Concepts ch4.pdf
Database System Concepts ch4.pdfDatabase System Concepts ch4.pdf
Database System Concepts ch4.pdf
UsamaAlZayan
 
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbjhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
WrushabhShirsat3
 
ch2.ppt
ch2.pptch2.ppt
Relational Model
Relational ModelRelational Model
Relational Model
alifmuhammad35
 

Similar to Intro to Relational Model (20)

Relational Algebra and relational queries .ppt
Relational Algebra and relational queries .pptRelational Algebra and relational queries .ppt
Relational Algebra and relational queries .ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Ch 3.pdf
Ch 3.pdfCh 3.pdf
Ch 3.pdf
 
DBMS _Relational model
DBMS _Relational modelDBMS _Relational model
DBMS _Relational model
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
 
Ch 2.pdf
Ch 2.pdfCh 2.pdf
Ch 2.pdf
 
Ch6 formal relational query languages
Ch6 formal relational query languages Ch6 formal relational query languages
Ch6 formal relational query languages
 
DBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQLDBMS_INTRODUCTION OF SQL
DBMS_INTRODUCTION OF SQL
 
Ch3
Ch3Ch3
Ch3
 
ch6.pptx
ch6.pptxch6.pptx
ch6.pptx
 
Database System Concepts ch4.pdf
Database System Concepts ch4.pdfDatabase System Concepts ch4.pdf
Database System Concepts ch4.pdf
 
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybbjhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
jhbuhbhujnhyubhbuybuybuybbuhyybuybuybuybybyubyubybybb
 
ch2.ppt
ch2.pptch2.ppt
ch2.ppt
 
Relational Model
Relational ModelRelational Model
Relational Model
 

Recently uploaded

AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 

Recently uploaded (20)

AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 

Intro to Relational Model

  • 1. Database System Concepts, 7th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Chapter 2: Intro to Relational Model
  • 2. ©Silberschatz, Korth and Sudarshan 2.2 Database System Concepts - 7th Edition Outline  Structure of Relational Databases  Database Schema  Keys  Schema Diagrams  Relational Query Languages  The Relational Algebra
  • 3. ©Silberschatz, Korth and Sudarshan 2.3 Database System Concepts - 7th Edition Example of a Instructor Relation attributes (or columns) tuples (or rows)
  • 4. ©Silberschatz, Korth and Sudarshan 2.4 Database System Concepts - 7th Edition Relation Schema and Instance  A1, A2, …, An are attributes  R = (A1, A2, …, An ) is a relation schema Example: instructor = (ID, name, dept_name, salary)  A relation instance r defined over schema R is denoted by r (R).  The current values a relation are specified by a table  An element t of relation r is called a tuple and is represented by a row in a table
  • 5. ©Silberschatz, Korth and Sudarshan 2.5 Database System Concepts - 7th Edition Attributes  The set of allowed values for each attribute is called the domain of the attribute  Attribute values are (normally) required to be atomic; that is, indivisible  The special value null is a member of every domain. Indicated that the value is “unknown”  The null value causes complications in the definition of many operations
  • 6. ©Silberschatz, Korth and Sudarshan 2.6 Database System Concepts - 7th Edition Relations are Unordered  Order of tuples is irrelevant (tuples may be stored in an arbitrary order)  Example: instructor relation with unordered tuples
  • 7. ©Silberschatz, Korth and Sudarshan 2.7 Database System Concepts - 7th Edition Database Schema  Database schema -- is the logical structure of the database.  Database instance -- is a snapshot of the data in the database at a given instant in time.  Example: • schema: instructor (ID, name, dept_name, salary) • Instance:
  • 8. ©Silberschatz, Korth and Sudarshan 2.8 Database System Concepts - 7th Edition Keys  Let K  R  K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R) • Example: {ID} and {ID,name} are both superkeys of instructor.  Superkey K is a candidate key if K is minimal Example: {ID} is a candidate key for Instructor  One of the candidate keys is selected to be the primary key. • Which one?  Foreign key constraint: Value in one relation must appear in another • Referencing relation • Referenced relation • Example: dept_name in instructor is a foreign key from instructor referencing department
  • 9. ©Silberschatz, Korth and Sudarshan 2.9 Database System Concepts - 7th Edition Schema Diagram for University Database
  • 10. ©Silberschatz, Korth and Sudarshan 2.10 Database System Concepts - 7th Edition Relational Query Languages  Procedural versus non-procedural, or declarative  “Pure” languages: • Relational algebra • Tuple relational calculus • Domain relational calculus  The above 3 pure languages are equivalent in computing power  We will concentrate in this chapter on relational algebra • Not Turing-machine equivalent • Consists of 6 basic operations
  • 11. ©Silberschatz, Korth and Sudarshan 2.11 Database System Concepts - 7th Edition Relational Algebra  A procedural language consisting of a set of operations that take one or two relations as input and produce a new relation as their result.  Six basic operators • select:  • project:  • union:  • set difference: – • Cartesian product: x • rename: 
  • 12. ©Silberschatz, Korth and Sudarshan 2.12 Database System Concepts - 7th Edition Select Operation  The select operation selects tuples that satisfy a given predicate.  Notation:  p (r)  p is called the selection predicate  Example: select those tuples of the instructor relation where the instructor is in the “Physics” department. • Query  dept_name=“Physics” (instructor) • Result
  • 13. ©Silberschatz, Korth and Sudarshan 2.13 Database System Concepts - 7th Edition Select Operation (Cont.)  We allow comparisons using =, , >, . <.  in the selection predicate.  We can combine several predicates into a larger predicate by using the connectives:  (and),  (or),  (not)  Example: Find the instructors in Physics with a salary greater $90,000, we write:  dept_name=“Physics”  salary > 90,000 (instructor)  The select predicate may include comparisons between two attributes. • Example, find all departments whose name is the same as their building name: •  dept_name=building (department)
  • 14. ©Silberschatz, Korth and Sudarshan 2.14 Database System Concepts - 7th Edition Project Operation  A unary operation that returns its argument relation, with certain attributes left out.  Notation:  A1,A2,A3 ….Ak (r) where A1, A2, …, Ak are attribute names and r is a relation name.  The result is defined as the relation of k columns obtained by erasing the columns that are not listed  Duplicate rows removed from result, since relations are sets
  • 15. ©Silberschatz, Korth and Sudarshan 2.15 Database System Concepts - 7th Edition Project Operation Example  Example: eliminate the dept_name attribute of instructor  Query: ID, name, salary (instructor)  Result:
  • 16. ©Silberschatz, Korth and Sudarshan 2.16 Database System Concepts - 7th Edition Composition of Relational Operations  The result of a relational-algebra operation is relation and therefore of relational-algebra operations can be composed together into a relational-algebra expression.  Consider the query -- Find the names of all instructors in the Physics department. name( dept_name =“Physics” (instructor))  Instead of giving the name of a relation as the argument of the projection operation, we give an expression that evaluates to a relation.
  • 17. ©Silberschatz, Korth and Sudarshan 2.17 Database System Concepts - 7th Edition Cartesian-Product Operation  The Cartesian-product operation (denoted by X) allows us to combine information from any two relations.  Example: the Cartesian product of the relations instructor and teaches is written as: instructor X teaches  We construct a tuple of the result out of each possible pair of tuples: one from the instructor relation and one from the teaches relation (see next slide)  Since the instructor ID appears in both relations we distinguish between these attribute by attaching to the attribute the name of the relation from which the attribute originally came. • instructor.ID • teaches.ID
  • 18. ©Silberschatz, Korth and Sudarshan 2.18 Database System Concepts - 7th Edition The instructor X teaches table
  • 19. ©Silberschatz, Korth and Sudarshan 2.19 Database System Concepts - 7th Edition Join Operation  The Cartesian-Product instructor X teaches associates every tuple of instructor with every tuple of teaches. • Most of the resulting rows have information about instructors who did NOT teach a particular course.  To get only those tuples of “instructor X teaches “ that pertain to instructors and the courses that they taught, we write:  instructor.id = teaches.id (instructor x teaches )) • We get only those tuples of “instructor X teaches” that pertain to instructors and the courses that they taught.  The result of this expression, shown in the next slide
  • 20. ©Silberschatz, Korth and Sudarshan 2.20 Database System Concepts - 7th Edition Join Operation (Cont.)  The table corresponding to:  instructor.id = teaches.id (instructor x teaches))
  • 21. ©Silberschatz, Korth and Sudarshan 2.21 Database System Concepts - 7th Edition Join Operation (Cont.)  The join operation allows us to combine a select operation and a Cartesian-Product operation into a single operation.  Consider relations r (R) and s (S)  Let “theta” be a predicate on attributes in the schema R “union” S. The join operation r ⋈𝜃 s is defined as follows: 𝑟 ⋈𝜃 𝑠 = 𝜎𝜃 (𝑟 × 𝑠)  Thus  instructor.id = teaches.id (instructor x teaches ))  Can equivalently be written as instructor ⋈ Instructor.id = teaches.id teaches.
  • 22. ©Silberschatz, Korth and Sudarshan 2.22 Database System Concepts - 7th Edition Union Operation  The union operation allows us to combine two relations  Notation: r  s  For r  s to be valid. 1. r, s must have the same arity (same number of attributes) 2. The attribute domains must be compatible (example: 2nd column of r deals with the same type of values as does the 2nd column of s)  Example: to find all courses taught in the Fall 2017 semester, or in the Spring 2018 semester, or in both course_id ( semester=“Fall” Λ year=2017 (section))  course_id ( semester=“Spring” Λ year=2018 (section))
  • 23. ©Silberschatz, Korth and Sudarshan 2.23 Database System Concepts - 7th Edition Union Operation (Cont.)  Result of: course_id ( semester=“Fall” Λ year=2017 (section))  course_id ( semester=“Spring” Λ year=2018 (section))
  • 24. ©Silberschatz, Korth and Sudarshan 2.24 Database System Concepts - 7th Edition Set-Intersection Operation  The set-intersection operation allows us to find tuples that are in both the input relations.  Notation: r  s  Assume: • r, s have the same arity • attributes of r and s are compatible  Example: Find the set of all courses taught in both the Fall 2017 and the Spring 2018 semesters. course_id ( semester=“Fall” Λ year=2017 (section))  course_id ( semester=“Spring” Λ year=2018 (section)) • Result
  • 25. ©Silberschatz, Korth and Sudarshan 2.25 Database System Concepts - 7th Edition Set Difference Operation  The set-difference operation allows us to find tuples that are in one relation but are not in another.  Notation r – s  Set differences must be taken between compatible relations. • r and s must have the same arity • attribute domains of r and s must be compatible  Example: to find all courses taught in the Fall 2017 semester, but not in the Spring 2018 semester course_id ( semester=“Fall” Λ year=2017 (section)) − course_id ( semester=“Spring” Λ year=2018 (section))
  • 26. ©Silberschatz, Korth and Sudarshan 2.26 Database System Concepts - 7th Edition The Assignment Operation  It is convenient at times to write a relational-algebra expression by assigning parts of it to temporary relation variables.  The assignment operation is denoted by  and works like assignment in a programming language.  Example: Find all instructor in the “Physics” and Music department. Physics   dept_name=“Physics” (instructor) Music   dept_name=“Music” (instructor) Physics  Music  With the assignment operation, a query can be written as a sequential program consisting of a series of assignments followed by an expression whose value is displayed as the result of the query.
  • 27. ©Silberschatz, Korth and Sudarshan 2.27 Database System Concepts - 7th Edition The Rename Operation  The results of relational-algebra expressions do not have a name that we can use to refer to them. The rename operator,  , is provided for that purpose  The expression: x (E) returns the result of expression E under the name x  Another form of the rename operation: x(A1,A2, .. An) (E)
  • 28. ©Silberschatz, Korth and Sudarshan 2.28 Database System Concepts - 7th Edition Equivalent Queries  There is more than one way to write a query in relational algebra.  Example: Find information about courses taught by instructors in the Physics department with salary greater than 90,000  Query 1  dept_name=“Physics”  salary > 90,000 (instructor)  Query 2  dept_name=“Physics” ( salary > 90.000 (instructor))  The two queries are not identical; they are, however, equivalent -- they give the same result on any database.
  • 29. ©Silberschatz, Korth and Sudarshan 2.29 Database System Concepts - 7th Edition Equivalent Queries  There is more than one way to write a query in relational algebra.  Example: Find information about courses taught by instructors in the Physics department  Query 1 dept_name=“Physics” (instructor ⋈ instructor.ID = teaches.ID teaches)  Query 2 (dept_name=“Physics” (instructor)) ⋈ instructor.ID = teaches.ID teaches  The two queries are not identical; they are, however, equivalent -- they give the same result on any database.
  • 30. ©Silberschatz, Korth and Sudarshan 2.30 Database System Concepts - 7th Edition End of Chapter 2