SlideShare a Scribd company logo
1 of 35
6 September 2019 1
Lesson 03
The Relational Model
6 September 2019 2
 Relational Databases
 represent data as a collection of tables
 each row in a table represents a collection of related values
Example
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
6 September 2019 S M Irteza / Dr Rafi Ullah 3
Relational Model
 Why is it called relational?
 a table is similar to the concept of a relation in mathematics
6 September 2019 S M Irteza / Dr Rafi Ullah 4
Relation
 Set/Subset
Examples of sets
D1 = {blue; yellow; white} and D2 ={ 1 , 2 }
 Tuple
Examples of tuples
– order of the elements within the tuple is important
< blue, blue > and < yellow, 1 , Paris >
6 September 2019 5
Relation
 Consider D1 = {blue; yellow; white} and D2 = {1; 2}
Cartesian Product
 The set of all (binary) tuples such that the first argument
belongs to D1 and the second argument belongs to D2 is
denoted D1xD2.
 A relation on D1xD2 is a collection of tuples < x, y > where all x’s
are taken from D1 and all y’s are taken from D2.
 In other words, a relation on D1xD2 is a subset of D1xD2.
6 September 2019 6
 Example:
D1 = {blue, yellow, white} and D2 = { 1 , 2}
D1xD2
{ < blue, 1 >,< blue, 2 >,
< yellow, 1 >,< yellow, 2 >,
< white, 1 >,< white, 2 > }
6 September 2019 7
Relational Model
 Association between tables and relations
 Rows in a table are associated with the tuples in the relation
 Columns in a table are associated with the arguments in the
tuples
 The columns are usually called attributes
 Number of attributes = degree of the relation
6 September 2019 8
Relational Model
Concepts carried over
 The sets of the relations are called domains in the relational model
 Domains define all possible values in the columns in the table
Less obvious implications to the model
 Tuples are unordered
 Location of the attributes within the relation is irrelevant
 but the position of the values in the tuple should match their logical
meaning
 Because a relation is a set of tuples, there are no duplicates
 tuples can always be uniquely identified
6 September 2019 9
Important Dissimilarity
 Domains are required to be atomic
 In other words, elements of the domain are indivisible units
6 September 2019 10
Relational Model – Quick Recap
 Tables (relations)
 Rows (tuples)
 Columns (attributes)
 Unordered tuples
 Atomic attributes
 No duplicate tuples
 Domains
6 September 2019 11
Relational Data Structure
 Table is the Data Structure for relational model
 Relation = Table
 name of this relation is S.
 Tuple = Row
 This relation has 5 tuples
 Each tuple represents a record of one supplier, so tuples
are seldom called records also.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
6 September 2019 12
Relational Data Structure
 Cardinality = # of rows with data in the relation
 so for S, cardinality = 5.
 Attribute = Columns or fields.
 Degree = # of columns or fields of a relation.
 The relation S has a degree of 4.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
6 September 2019 13
Relational Data Structure
 Domain = A pool of legal values
 For example:
 For S# we have S followed by a positive number.
 For Year we might have a four digit positive number between
1000 and 2003.
 Primary Key = A unique identifier, used to identify one
specific record from among all other records.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
6 September 2019 14
Relations
 A relation consists of 2 parts
 Heading:
 Consists of a fixed set of attributes or columns or fields.
 Defined through the DDL, and usually remains the
same.
 Body
 Consists of the tuples or rows or records.
 Time varying set, i.e., at different intervals of time
there may be different contents in the body of a
relation.
6 September 2019 15
RELVARS
 In the book, a relation is usually referred to as a
relation variable, or simply called relvar
 Because a relation is not constant at all the given
time intervals.
 Values might be different.
6 September 2019 16
2 Key Properties of Relations
 No Duplicate tuples
 In other words, not all fields are same
 All cells have a single value
 A relation which follows this rule is said to be in the
first normal form.
6 September 2019 17
Why Normalize?
 A Normalized relation provides a
 Simpler structure
 Simpler procedures
 FIRST NORMAL FORM
 One cell has one value ONLY
6 September 2019 18
Relational Integrity
 The ultimate purpose of a DB is to store
information about the real world.
 It is possible that some information submitted to
the DB does not correspond to any possible
configuration of the real world.
 negative salaries
 impossible dates: 30/02/1999
 negative quantities in stock, etc
6 September 2019 19
Relational Integrity Rules
- To prevent invalid or illegal values from occurring in the
database we have some rules
 Specific Integrity Rules
 Apply to a specific database, I.e. years may not be
less than zero, and 0 < age < 200 .
 General Integrity Rules
 Apply to all the relational databases.
 Like no two same tuples etc.
6 September 2019 20
Candidate Keys
 A relation might have more than one unique identifiers. We
simply choose one as our primary key.
 Attribute K (possibly composite) of relation R is a candidate
key for R , if it satisfies the following two properties.
 UNIQUENESS: no 2 tuples of relation R have the
same values of K.
 MINIMILITY: If K is composite then no subset of K
has the unique property.
- i.e. if you find any column that is unique, don’t add
any more column to the primary key, because this
column by itself is a suitable primary key
6 September 2019 21
Candidate Keys
 Composite Key Example
 (S#, sname)
 (P#,S#)
 (pname, sname, address, S#)
 Atomic Key Example
 S#
 P#
 sname
 pname
6 September 2019 22
Primary Keys and Alternate Keys
 A Unique Identifier.
 The primary key is chosen from a set of candidate
keys.
 The primary key is the candidate key chosen to be the
main key for the relation
 The other candidate keys are called alternate keys
 Not duplicable
 NULLS are not allowed in the primary key field.
6 September 2019 23
Primary Keys
 In the relation/table primary key is “S#”
 As sname, status and city are assumed to be
repeatable or can be duplicate.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
6 September 2019 24
Primary Keys
 The primary key in SP is (S#,
P#)
 It is composite, as there is no
single choice for P.K due to the
format of the table or data.
 So P.K = (S#, P#)
//composite P.K
 CAUTION:
 Do not be mistaken by seeing
the data at a time interval, in
the table and assuming your
primary keys.
S# P# QTY
S1 P1 300
S1 P2 200
S1 P3 400
S1 P4 200
S1 P5 100
S1 P6 100
S2 P1 300
S2 P2 400
S3 P2 200
S4 P2 200
S4 P4 300
S4 P5 400
Supplier & Parts SP
6 September 2019 25
Foreign Keys
 A foreign key is an attribute of one
relation R2 whose values are required to
match those values of the primary key
of some relation R1.
Foreign Keys
 Foreign Keys are used to link data in
two relations. A set of attributes in
the first (referencing) relation is a
foreign key if its value always either:
 Matches a candidate key value in the
second (referenced) relation; or
 Is wholly NULL.
 This is called Referential Integrity
6 September 2019 26
Foreign Keys: Example
Department:
DID is a Candidate Key for the
Department relation. Each entry
has a unique value for DID
Employee:
DID is a Foreign Key in the Employee
relation– each Employee’s DID value is
either NULL, or matches an entry in
the Department relation. This links
each employee to (at most) one
Department
6 September 2019 27
DID DName
13 Marketing
14 Accounts
15 Personnel
EID EName DID
15 Yunus Sami 13
16 Mirza Barki 14
17 Malik Jahan 13
18 Jan Sher NULL
Foreign Keys: Example
Student:
{First, Last} is a Candidate Key
for the Student relation – no
entries have the same value for
both First and Last.
Enrolment:
{First, Last} is a Foreign Key in the
Enrolment relation - each {First, Last}
pair matches exactly one entry in the
Student relation.
6 September 2019 S M Irteza / Dr Rafi Ullah 28
ID First Last
S01 Ahmad Khan
S02 Athar Khalid
S03 Sameer Shahid
S04 Sameer Khan
First Last Course
Ahmad Khan CS101
Ahmad Khan CS222
Sameer Shahid CS101
Sameer Khan CS222
6 September 2019 S M Irteza / Dr Rafi Ullah 29
Relational Integrity Rules
To prevent invalid or illegal values from occurring in the
database we have some rules
 Specific Integrity Rules
 Apply to a specific database, i.e., Years may not be
less than zero, and 0 < Age < 200 .
 General Integrity Rules
 Apply to all the relational databases.
 Like no two same tuples etc.
6 September 2019 S M Irteza / Dr Rafi Ullah 30
General Integrity Rules
We have basically two general integrity
rules
1. Entity Integrity Rule.
2. Referential Integrity Rule.
6 September 2019 S M Irteza / Dr Rafi Ullah 31
1: Entity Integrity Rule
 “No Component of the P.K of a relation is allowed to
accept NULLs”.
 NULL (null value) = unknown or missing value.
 Note that a NULL value is not zero, it is not infinity, or
negative, or FI value. It is simply non existent for the
system.
 P.K = (S#,NULL) is illegal.
6 September 2019 S M Irteza / Dr Rafi Ullah 32
2: Referential Integrity Rule
 “The DB must not contain any unmatched foreign key values”.
 e.g., shipment should not have S6 which is not in the suppliers
table as a P.K
 Any state of the DB that doesn't satisfy the integrity rules is
ILLEGAL.
S# SNAME STATUS CITY
S1 Smith 20 London
S2 Jones 10 Paris
S3 Blake 30 Paris
S4 Clark 20 London
S5 Adams 30 Athens
Supplier S
P# PNAME COLOR WEIGHT CITY
P1 Nut Red 12 London
P2 Bolt Green 17 Paris
P3 Screw Blue 17 Rome
P4 Screw Red 14 London
P5 Cam Blue 12 Paris
P6 Cog Red 19 London
Parts P
S# P# QTY
S1 P1 300
S1 P2 200
S1 P3 400
S1 P4 200
S1 P5 100
S1 P6 100
S2 P1 300
S2 P2 400
S3 P2 200
S4 P2 200
S4 P4 300
S4 P5 400
Supplier & Parts SP
6 September 2019 S M Irteza / Dr Rafi Ullah 33
How to Avoid Illegal States?
1. Simply reject any operation that would result in an
illegal state, for example:
 if we try to store “S5” in table S with an “S5” entry
existing, then the system should reject that.
2. Accept the operation but perform some additional
compensating operations in order to guarantee the
overall result is still in a legal state.
 E.g. to delete a supplier for which there exists some
shipments, lets say we try to delete “S3” from
supplier, so violation at shipment table occurs as
shipment had “S3” entry as a F.K.
6 September 2019 S M Irteza / Dr Rafi Ullah 34
CASCADING
 to delete a supplier for which there exists some shipments,
lets say we try to delete “S3” from supplier, so violation at
shipment table occurs as shipment had “S3” entry as a F.K.
 So what we can do is called “CASCADING”.
 In which deletion process does the following
 Deletes all entries for “S3” from shipment.
 And then deletes the supplier “S3” from supplier table.
 Now no violation will occur.
 This is called cascading.
6 September 2019 S M Irteza / Dr Rafi Ullah 35
End
END OF LESSON 03
(these slides were adapted from original slides of M Ali Shahid)

More Related Content

What's hot

Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Eddyzulham Mahluzydde
 
Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3Eddyzulham Mahluzydde
 
DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2YOGESH SINGH
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMSkoolkampus
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model IntroductionNishant Munjal
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data ModelSmriti Jain
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational modelATS SBGI MIRAJ
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...Raj vardhan
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Eddyzulham Mahluzydde
 
Relational database
Relational databaseRelational database
Relational databaseSanthiNivas
 
Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management systememailharmeet
 
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database ConstraintsThe Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraintssontumax
 
Relational database intro for marketers
Relational database intro for marketersRelational database intro for marketers
Relational database intro for marketersSteve Finlay
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An IntroductionRajeev Srivastava
 

What's hot (20)

Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1
 
Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3
 
DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2
 
Dbms relational data model and sql queries
Dbms relational data model and sql queries Dbms relational data model and sql queries
Dbms relational data model and sql queries
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
Relational model
Relational modelRelational model
Relational model
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
Database design
Database designDatabase design
Database design
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2
 
Relational model
Relational modelRelational model
Relational model
 
Relational database
Relational databaseRelational database
Relational database
 
Relational model
Relational modelRelational model
Relational model
 
Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management system
 
ch6
ch6ch6
ch6
 
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database ConstraintsThe Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
 
Relational database intro for marketers
Relational database intro for marketersRelational database intro for marketers
Relational database intro for marketers
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An Introduction
 

Similar to Lesson03 the relational model

2. relational model_150903
2. relational model_1509032. relational model_150903
2. relational model_150903Dika Handika
 
Relational model
Relational modelRelational model
Relational modelRUpaliLohar
 
Relational model
Relational modelRelational model
Relational modelRUpaliLohar
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.modellavya3
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdfLPhct2
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)Rai University
 
Fd & Normalization - Database Management System
Fd & Normalization - Database Management SystemFd & Normalization - Database Management System
Fd & Normalization - Database Management SystemDrishti Bhalla
 
relational algebra Tuple Relational Calculus - database management system
relational algebra Tuple Relational Calculus - database management systemrelational algebra Tuple Relational Calculus - database management system
relational algebra Tuple Relational Calculus - database management systemSurya Swaroop
 

Similar to Lesson03 the relational model (20)

2. relational model_150903
2. relational model_1509032. relational model_150903
2. relational model_150903
 
Relational model
Relational modelRelational model
Relational model
 
Relational model
Relational modelRelational model
Relational model
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
NMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.pptNMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.ppt
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
 
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
 
Lesson06 database design
Lesson06 database designLesson06 database design
Lesson06 database design
 
uniT 4 (1).pptx
uniT 4 (1).pptxuniT 4 (1).pptx
uniT 4 (1).pptx
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
 
DBMS-Unit-2.pptx
DBMS-Unit-2.pptxDBMS-Unit-2.pptx
DBMS-Unit-2.pptx
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Lesson07 e r modelling
Lesson07 e r modellingLesson07 e r modelling
Lesson07 e r modelling
 
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
 
Fd & Normalization - Database Management System
Fd & Normalization - Database Management SystemFd & Normalization - Database Management System
Fd & Normalization - Database Management System
 
DBMS UNIT1
DBMS UNIT1DBMS UNIT1
DBMS UNIT1
 
relational algebra Tuple Relational Calculus - database management system
relational algebra Tuple Relational Calculus - database management systemrelational algebra Tuple Relational Calculus - database management system
relational algebra Tuple Relational Calculus - database management system
 
Ch 6
Ch 6Ch 6
Ch 6
 
Unit03 dbms
Unit03 dbmsUnit03 dbms
Unit03 dbms
 
DBMS Part-2.pptx
DBMS Part-2.pptxDBMS Part-2.pptx
DBMS Part-2.pptx
 

More from Muhammad Sikandar Mustafa (17)

What is organizational behavior
What is organizational behaviorWhat is organizational behavior
What is organizational behavior
 
11. estimation-1
11. estimation-111. estimation-1
11. estimation-1
 
9. risk-management
9. risk-management9. risk-management
9. risk-management
 
8. project-management
8. project-management8. project-management
8. project-management
 
7. requirement-engineering
7. requirement-engineering7. requirement-engineering
7. requirement-engineering
 
6. software requirements
6. software requirements6. software requirements
6. software requirements
 
software process
software process software process
software process
 
software myths
software mythssoftware myths
software myths
 
software characteristics
software characteristicssoftware characteristics
software characteristics
 
overview introduction to Software Engineering
overview introduction to Software Engineeringoverview introduction to Software Engineering
overview introduction to Software Engineering
 
5. software process model
5. software process model5. software process model
5. software process model
 
Lesson02 database system architecture
Lesson02 database system architectureLesson02 database system architecture
Lesson02 database system architecture
 
Lesson01 Database introduction
Lesson01 Database introductionLesson01 Database introduction
Lesson01 Database introduction
 
Lesson00 intro to databases
Lesson00 intro to databasesLesson00 intro to databases
Lesson00 intro to databases
 
Lesson10 Database security
Lesson10 Database security Lesson10 Database security
Lesson10 Database security
 
Lesson08 tm recovery
Lesson08 tm recoveryLesson08 tm recovery
Lesson08 tm recovery
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter ppt
 

Recently uploaded

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 

Recently uploaded (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 

Lesson03 the relational model

  • 1. 6 September 2019 1 Lesson 03 The Relational Model
  • 2. 6 September 2019 2  Relational Databases  represent data as a collection of tables  each row in a table represents a collection of related values Example S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 3. 6 September 2019 S M Irteza / Dr Rafi Ullah 3 Relational Model  Why is it called relational?  a table is similar to the concept of a relation in mathematics
  • 4. 6 September 2019 S M Irteza / Dr Rafi Ullah 4 Relation  Set/Subset Examples of sets D1 = {blue; yellow; white} and D2 ={ 1 , 2 }  Tuple Examples of tuples – order of the elements within the tuple is important < blue, blue > and < yellow, 1 , Paris >
  • 5. 6 September 2019 5 Relation  Consider D1 = {blue; yellow; white} and D2 = {1; 2} Cartesian Product  The set of all (binary) tuples such that the first argument belongs to D1 and the second argument belongs to D2 is denoted D1xD2.  A relation on D1xD2 is a collection of tuples < x, y > where all x’s are taken from D1 and all y’s are taken from D2.  In other words, a relation on D1xD2 is a subset of D1xD2.
  • 6. 6 September 2019 6  Example: D1 = {blue, yellow, white} and D2 = { 1 , 2} D1xD2 { < blue, 1 >,< blue, 2 >, < yellow, 1 >,< yellow, 2 >, < white, 1 >,< white, 2 > }
  • 7. 6 September 2019 7 Relational Model  Association between tables and relations  Rows in a table are associated with the tuples in the relation  Columns in a table are associated with the arguments in the tuples  The columns are usually called attributes  Number of attributes = degree of the relation
  • 8. 6 September 2019 8 Relational Model Concepts carried over  The sets of the relations are called domains in the relational model  Domains define all possible values in the columns in the table Less obvious implications to the model  Tuples are unordered  Location of the attributes within the relation is irrelevant  but the position of the values in the tuple should match their logical meaning  Because a relation is a set of tuples, there are no duplicates  tuples can always be uniquely identified
  • 9. 6 September 2019 9 Important Dissimilarity  Domains are required to be atomic  In other words, elements of the domain are indivisible units
  • 10. 6 September 2019 10 Relational Model – Quick Recap  Tables (relations)  Rows (tuples)  Columns (attributes)  Unordered tuples  Atomic attributes  No duplicate tuples  Domains
  • 11. 6 September 2019 11 Relational Data Structure  Table is the Data Structure for relational model  Relation = Table  name of this relation is S.  Tuple = Row  This relation has 5 tuples  Each tuple represents a record of one supplier, so tuples are seldom called records also. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 12. 6 September 2019 12 Relational Data Structure  Cardinality = # of rows with data in the relation  so for S, cardinality = 5.  Attribute = Columns or fields.  Degree = # of columns or fields of a relation.  The relation S has a degree of 4. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 13. 6 September 2019 13 Relational Data Structure  Domain = A pool of legal values  For example:  For S# we have S followed by a positive number.  For Year we might have a four digit positive number between 1000 and 2003.  Primary Key = A unique identifier, used to identify one specific record from among all other records. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 14. 6 September 2019 14 Relations  A relation consists of 2 parts  Heading:  Consists of a fixed set of attributes or columns or fields.  Defined through the DDL, and usually remains the same.  Body  Consists of the tuples or rows or records.  Time varying set, i.e., at different intervals of time there may be different contents in the body of a relation.
  • 15. 6 September 2019 15 RELVARS  In the book, a relation is usually referred to as a relation variable, or simply called relvar  Because a relation is not constant at all the given time intervals.  Values might be different.
  • 16. 6 September 2019 16 2 Key Properties of Relations  No Duplicate tuples  In other words, not all fields are same  All cells have a single value  A relation which follows this rule is said to be in the first normal form.
  • 17. 6 September 2019 17 Why Normalize?  A Normalized relation provides a  Simpler structure  Simpler procedures  FIRST NORMAL FORM  One cell has one value ONLY
  • 18. 6 September 2019 18 Relational Integrity  The ultimate purpose of a DB is to store information about the real world.  It is possible that some information submitted to the DB does not correspond to any possible configuration of the real world.  negative salaries  impossible dates: 30/02/1999  negative quantities in stock, etc
  • 19. 6 September 2019 19 Relational Integrity Rules - To prevent invalid or illegal values from occurring in the database we have some rules  Specific Integrity Rules  Apply to a specific database, I.e. years may not be less than zero, and 0 < age < 200 .  General Integrity Rules  Apply to all the relational databases.  Like no two same tuples etc.
  • 20. 6 September 2019 20 Candidate Keys  A relation might have more than one unique identifiers. We simply choose one as our primary key.  Attribute K (possibly composite) of relation R is a candidate key for R , if it satisfies the following two properties.  UNIQUENESS: no 2 tuples of relation R have the same values of K.  MINIMILITY: If K is composite then no subset of K has the unique property. - i.e. if you find any column that is unique, don’t add any more column to the primary key, because this column by itself is a suitable primary key
  • 21. 6 September 2019 21 Candidate Keys  Composite Key Example  (S#, sname)  (P#,S#)  (pname, sname, address, S#)  Atomic Key Example  S#  P#  sname  pname
  • 22. 6 September 2019 22 Primary Keys and Alternate Keys  A Unique Identifier.  The primary key is chosen from a set of candidate keys.  The primary key is the candidate key chosen to be the main key for the relation  The other candidate keys are called alternate keys  Not duplicable  NULLS are not allowed in the primary key field.
  • 23. 6 September 2019 23 Primary Keys  In the relation/table primary key is “S#”  As sname, status and city are assumed to be repeatable or can be duplicate. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S
  • 24. 6 September 2019 24 Primary Keys  The primary key in SP is (S#, P#)  It is composite, as there is no single choice for P.K due to the format of the table or data.  So P.K = (S#, P#) //composite P.K  CAUTION:  Do not be mistaken by seeing the data at a time interval, in the table and assuming your primary keys. S# P# QTY S1 P1 300 S1 P2 200 S1 P3 400 S1 P4 200 S1 P5 100 S1 P6 100 S2 P1 300 S2 P2 400 S3 P2 200 S4 P2 200 S4 P4 300 S4 P5 400 Supplier & Parts SP
  • 25. 6 September 2019 25 Foreign Keys  A foreign key is an attribute of one relation R2 whose values are required to match those values of the primary key of some relation R1.
  • 26. Foreign Keys  Foreign Keys are used to link data in two relations. A set of attributes in the first (referencing) relation is a foreign key if its value always either:  Matches a candidate key value in the second (referenced) relation; or  Is wholly NULL.  This is called Referential Integrity 6 September 2019 26
  • 27. Foreign Keys: Example Department: DID is a Candidate Key for the Department relation. Each entry has a unique value for DID Employee: DID is a Foreign Key in the Employee relation– each Employee’s DID value is either NULL, or matches an entry in the Department relation. This links each employee to (at most) one Department 6 September 2019 27 DID DName 13 Marketing 14 Accounts 15 Personnel EID EName DID 15 Yunus Sami 13 16 Mirza Barki 14 17 Malik Jahan 13 18 Jan Sher NULL
  • 28. Foreign Keys: Example Student: {First, Last} is a Candidate Key for the Student relation – no entries have the same value for both First and Last. Enrolment: {First, Last} is a Foreign Key in the Enrolment relation - each {First, Last} pair matches exactly one entry in the Student relation. 6 September 2019 S M Irteza / Dr Rafi Ullah 28 ID First Last S01 Ahmad Khan S02 Athar Khalid S03 Sameer Shahid S04 Sameer Khan First Last Course Ahmad Khan CS101 Ahmad Khan CS222 Sameer Shahid CS101 Sameer Khan CS222
  • 29. 6 September 2019 S M Irteza / Dr Rafi Ullah 29 Relational Integrity Rules To prevent invalid or illegal values from occurring in the database we have some rules  Specific Integrity Rules  Apply to a specific database, i.e., Years may not be less than zero, and 0 < Age < 200 .  General Integrity Rules  Apply to all the relational databases.  Like no two same tuples etc.
  • 30. 6 September 2019 S M Irteza / Dr Rafi Ullah 30 General Integrity Rules We have basically two general integrity rules 1. Entity Integrity Rule. 2. Referential Integrity Rule.
  • 31. 6 September 2019 S M Irteza / Dr Rafi Ullah 31 1: Entity Integrity Rule  “No Component of the P.K of a relation is allowed to accept NULLs”.  NULL (null value) = unknown or missing value.  Note that a NULL value is not zero, it is not infinity, or negative, or FI value. It is simply non existent for the system.  P.K = (S#,NULL) is illegal.
  • 32. 6 September 2019 S M Irteza / Dr Rafi Ullah 32 2: Referential Integrity Rule  “The DB must not contain any unmatched foreign key values”.  e.g., shipment should not have S6 which is not in the suppliers table as a P.K  Any state of the DB that doesn't satisfy the integrity rules is ILLEGAL. S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens Supplier S P# PNAME COLOR WEIGHT CITY P1 Nut Red 12 London P2 Bolt Green 17 Paris P3 Screw Blue 17 Rome P4 Screw Red 14 London P5 Cam Blue 12 Paris P6 Cog Red 19 London Parts P S# P# QTY S1 P1 300 S1 P2 200 S1 P3 400 S1 P4 200 S1 P5 100 S1 P6 100 S2 P1 300 S2 P2 400 S3 P2 200 S4 P2 200 S4 P4 300 S4 P5 400 Supplier & Parts SP
  • 33. 6 September 2019 S M Irteza / Dr Rafi Ullah 33 How to Avoid Illegal States? 1. Simply reject any operation that would result in an illegal state, for example:  if we try to store “S5” in table S with an “S5” entry existing, then the system should reject that. 2. Accept the operation but perform some additional compensating operations in order to guarantee the overall result is still in a legal state.  E.g. to delete a supplier for which there exists some shipments, lets say we try to delete “S3” from supplier, so violation at shipment table occurs as shipment had “S3” entry as a F.K.
  • 34. 6 September 2019 S M Irteza / Dr Rafi Ullah 34 CASCADING  to delete a supplier for which there exists some shipments, lets say we try to delete “S3” from supplier, so violation at shipment table occurs as shipment had “S3” entry as a F.K.  So what we can do is called “CASCADING”.  In which deletion process does the following  Deletes all entries for “S3” from shipment.  And then deletes the supplier “S3” from supplier table.  Now no violation will occur.  This is called cascading.
  • 35. 6 September 2019 S M Irteza / Dr Rafi Ullah 35 End END OF LESSON 03 (these slides were adapted from original slides of M Ali Shahid)

Editor's Notes

  1. Syed M Irteza