SlideShare a Scribd company logo
1 of 27
Concepts of Database Management
Seventh Edition
Chapter 4
Keys and Relationship
Objectives
• Understand different type of keys in a Table.
• Understand the different type of Table relationship
• Identify the primary key and foreign key to create a
relationship.
• Create primary and foreign key in an actual DBMS
2
Table Relationship
• Remember in Chapter 1 we discuss the hierarchy
of data, namely:
– Field or Column
– Record or Row
– Table or File
– Database
• Now, Tables normally does not stand alone, that
is, in the modern database software like MS
Access, mySQL, Oracle or MS SQL, table(s)
normally has relationship with another table.
3
Three Types of Relationship
• There are three types of table relationship:
– One to one or denoted as 1:1
– One to many or denoted as 1:M
– Many to Many or denoted as M:N
4
Examples of One-to-One Relationship
• A student belongs to only one Program
• A student has one and only ID
• An employee has one computer assign
• Could you name your own example?
5
Examples of One-to-Many
Relationship
• A Division could have more than one Program
offered
• A Program could have many students enrolled
• Could you name your own example?
6
Examples of Many-to-Many
Relationship
• A student could take many course and a course
could have many students
• An author could have many books and a book
could have many author
• A music album could have many artists/performers
and an artist/performer could have many albums
• Could you name your own example?
7
Key in a table
• A key in a table is a field or group of fields that
creates identity, makes relationship with another
table and/or make a table more efficient.
8
Primary Key & Foreign
• A Primary key is a key that uniquely identifies a
row in each table. It is normally denoted with its
first two letters, namely, PK.
• A Foreign key is a key borrowed from another
related table (that’s why its foreign) in order to
make the relationship between two tables. It is
normally denoted with its first two letters, namely,
FK.
9
Examples from Premier Database –
Primary Key
10
Repnum uniquely identifies the Rep table
and is the primary key of this table.
Examples from Premier Database –
Primary Key
11
Customernum uniquely identifies the Customer table
and is the primary key of this table.
Examples from Premier Database –
Primary Key
12
Ordernum and Partnum makes up the primary key
Of the OrderLine table. This is what is known as a Composite
Primary key, that is, primary key that is made up of more than
one field.
Examples from Premier Database
• Could you identify any more primary keys from
Premier Database?
13
Examples from Premier Database –
Foreign Key
14
Repnum is a Foreign key borrowed from Rep table
Examples from Premier Database
• Could you identify any more foreign keys from
Premier Database?
15
Notation example
• One Rep could have one or more customer (one to many) using
Primary and foreign key to create the relationship.
16
Customer
Customernum (PK)
Customername
Street
City
State
Zip
Balance
CreditLimit
Repnum (FK)
Rep
Repnum (PK)
Lastname
Firstname
Street
City
State
Zip
Commission
Rate
1
M
Notation example
• Always remember the many side has the Foreign key. In this
case the many side is on the Customer table and therefore has the
foreign key Repnum which is the primary key of Rep table.
17
Customer
Customernum (PK)
Customername
Street
City
State
Zip
Balance
CreditLimit
Repnum (FK)
Rep
Repnum (PK)
Lastname
Firstname
Street
City
State
Zip
Commission
Rate
1
M
Examples from Premier Database
• Could you identify the different relationship among
tables in Premier Database because of the Primary
and Foreign keys?
18
Referential Integrity
• Referential Integrity means that the Foreign key
must match in terms of actual values and data
types with the related Primary Key.
19
Referential Integrity
• Example:
• The foreign key RepNum in Customer must match
with the primary key RepNum in Rep table.
20
Referential Integrity
• In terms of Data Type
• Customer RepNum (Foreign Key) has Text Data
type and Rep RepNum (Primary Key) has also Text
Data type.
21
Seatwork
22
• Colonial and Solmaris
• Identify the primary key and foreign keys for each
table. Put the name of the table and name its
primary key and if there is a foreign key identify the
foreign key.
• Identify how each table that has the foreign key
relates to another table. See slide No. 16 and 17
Demo in creating Primary and Foreign
Key in MS Access
23
Referential Integrity
• In terms of actual Values
24
Non-Graded Seatwork
25
• Colonial and Solmaris
– Check the tables that are related to each other and
then check data types for both Foreign and Primary
Keys that are related.
– Check also the values of the related Primary Keys if
you could find it in the related Foreign keys.
– Try to enter values in the Foreign Key that could not
be found in related table that has the Primary Key.
Did MS Access pops out an error message? What
does it say?
On-your-own Exercise
26
– Imagine we want to make a simple appointment database for a small
clinic here in Pohnpei with a fictitious name Health Wealth clinic. And
the database would record appointments for Patients with their
Doctor on a given date.
– Now a Patient could have one or more appointments in Health Wealth
clinic to one or more Doctor.
– A Doctor could also have one or more appointment with one or more
patients every day.
– Create a database in MS Access named Keys-Lastname.accdb
– Create three tables, namely, Patients, Doctors and Appointments.
– Create necessary fields for each table that you think should be there.
– Create a Primary Key for each tables.
– And create also Foreign keys if necessary to create relationship
among tables.
– Use the Database Tools to create the Relationship among tables after
you created both the Primary Keys and Foreign Keys.
– Enter at least 3 doctors, 5 patients and 8 appointments
– Send your work to nationalcis@gmail.com with the title Database
with Keys activity
Summary (continued)
• Modern database normally has tables that has
logical relationships with one another.
• Three primary type of relationships are one-to-one,
one-to-many and many-to-many.
• Each row/record in a Table should be unique using
a Primary Key
• To create a relationship among tables you must
have the Foreign key on the other table.
• Referential Integrity protects the integrity of your
data by matching both your Primary key and
Foreign in terms of Data types and actual values.
27

More Related Content

Similar to IS230 - Chapter 4 - Keys and Relationship - Revised.ppt

Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelKunal Anand
 
overview of database concept
overview of database conceptoverview of database concept
overview of database conceptgourav kottawar
 
1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docx
1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docx1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docx
1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docxhyacinthshackley2629
 
chapter08 - Database fundamentals.pdf
chapter08 - Database fundamentals.pdfchapter08 - Database fundamentals.pdf
chapter08 - Database fundamentals.pdfsatonaka3
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Processmussawir20
 
Presentation DBMS (1)
Presentation DBMS (1)Presentation DBMS (1)
Presentation DBMS (1)Ali Raza
 
L2 identifying photos
L2   identifying photosL2   identifying photos
L2 identifying photosMrJRogers
 
Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & RelationshipBellal Hossain
 
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdfDBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Relational Theory for Budding Einsteins -- LonestarPHP 2016
Relational Theory for Budding Einsteins -- LonestarPHP 2016Relational Theory for Budding Einsteins -- LonestarPHP 2016
Relational Theory for Budding Einsteins -- LonestarPHP 2016Dave Stokes
 

Similar to IS230 - Chapter 4 - Keys and Relationship - Revised.ppt (20)

Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data Model
 
DBMS:Relational Modal
DBMS:Relational ModalDBMS:Relational Modal
DBMS:Relational Modal
 
overview of database concept
overview of database conceptoverview of database concept
overview of database concept
 
Year 11 DATA PROCESSING 1st Term
Year 11 DATA PROCESSING 1st TermYear 11 DATA PROCESSING 1st Term
Year 11 DATA PROCESSING 1st Term
 
1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docx
1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docx1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docx
1Copyright © 2014 Pearson Education, Inc. Publishing as Pren.docx
 
chapter08 - Database fundamentals.pdf
chapter08 - Database fundamentals.pdfchapter08 - Database fundamentals.pdf
chapter08 - Database fundamentals.pdf
 
Access 05
Access 05Access 05
Access 05
 
Database
Database Database
Database
 
demo2.ppt
demo2.pptdemo2.ppt
demo2.ppt
 
Relational_Model.ppt
Relational_Model.pptRelational_Model.ppt
Relational_Model.ppt
 
Relational model
Relational modelRelational model
Relational model
 
Analysis 3 1
Analysis 3 1Analysis 3 1
Analysis 3 1
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
 
Presentation DBMS (1)
Presentation DBMS (1)Presentation DBMS (1)
Presentation DBMS (1)
 
L2 identifying photos
L2   identifying photosL2   identifying photos
L2 identifying photos
 
Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & Relationship
 
Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to Databases
 
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdfDBMS VIVA QUESTIONS_CODERS LODGE.pdf
DBMS VIVA QUESTIONS_CODERS LODGE.pdf
 
Relational Theory for Budding Einsteins -- LonestarPHP 2016
Relational Theory for Budding Einsteins -- LonestarPHP 2016Relational Theory for Budding Einsteins -- LonestarPHP 2016
Relational Theory for Budding Einsteins -- LonestarPHP 2016
 
MS ACCESS
MS ACCESSMS ACCESS
MS ACCESS
 

More from wondmhunegn

Microsoft Access.ppt
Microsoft Access.pptMicrosoft Access.ppt
Microsoft Access.pptwondmhunegn
 
Module 2 Slides.ppt
Module 2 Slides.pptModule 2 Slides.ppt
Module 2 Slides.pptwondmhunegn
 
ETE105_lecture 3.ppt
ETE105_lecture 3.pptETE105_lecture 3.ppt
ETE105_lecture 3.pptwondmhunegn
 
BasicComputerParts.ppt
BasicComputerParts.pptBasicComputerParts.ppt
BasicComputerParts.pptwondmhunegn
 
Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptxwondmhunegn
 
MS-Access Tables Forms Queries Reports.ppt
MS-Access Tables Forms Queries Reports.pptMS-Access Tables Forms Queries Reports.ppt
MS-Access Tables Forms Queries Reports.pptwondmhunegn
 
DatabaseFundamentals.ppt
DatabaseFundamentals.pptDatabaseFundamentals.ppt
DatabaseFundamentals.pptwondmhunegn
 
Data Types and Field Properties.ppt
Data Types and Field Properties.pptData Types and Field Properties.ppt
Data Types and Field Properties.pptwondmhunegn
 

More from wondmhunegn (11)

sql-basic.ppt
sql-basic.pptsql-basic.ppt
sql-basic.ppt
 
Microsoft Access.ppt
Microsoft Access.pptMicrosoft Access.ppt
Microsoft Access.ppt
 
Module 2 Slides.ppt
Module 2 Slides.pptModule 2 Slides.ppt
Module 2 Slides.ppt
 
ETE105_lecture 3.ppt
ETE105_lecture 3.pptETE105_lecture 3.ppt
ETE105_lecture 3.ppt
 
BasicComputerParts.ppt
BasicComputerParts.pptBasicComputerParts.ppt
BasicComputerParts.ppt
 
tree.ppt
tree.ppttree.ppt
tree.ppt
 
Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptx
 
MS-Access Tables Forms Queries Reports.ppt
MS-Access Tables Forms Queries Reports.pptMS-Access Tables Forms Queries Reports.ppt
MS-Access Tables Forms Queries Reports.ppt
 
DatabaseFundamentals.ppt
DatabaseFundamentals.pptDatabaseFundamentals.ppt
DatabaseFundamentals.ppt
 
Data Types and Field Properties.ppt
Data Types and Field Properties.pptData Types and Field Properties.ppt
Data Types and Field Properties.ppt
 
Template.pptx
Template.pptxTemplate.pptx
Template.pptx
 

Recently uploaded

Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 

Recently uploaded (20)

CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 

IS230 - Chapter 4 - Keys and Relationship - Revised.ppt

  • 1. Concepts of Database Management Seventh Edition Chapter 4 Keys and Relationship
  • 2. Objectives • Understand different type of keys in a Table. • Understand the different type of Table relationship • Identify the primary key and foreign key to create a relationship. • Create primary and foreign key in an actual DBMS 2
  • 3. Table Relationship • Remember in Chapter 1 we discuss the hierarchy of data, namely: – Field or Column – Record or Row – Table or File – Database • Now, Tables normally does not stand alone, that is, in the modern database software like MS Access, mySQL, Oracle or MS SQL, table(s) normally has relationship with another table. 3
  • 4. Three Types of Relationship • There are three types of table relationship: – One to one or denoted as 1:1 – One to many or denoted as 1:M – Many to Many or denoted as M:N 4
  • 5. Examples of One-to-One Relationship • A student belongs to only one Program • A student has one and only ID • An employee has one computer assign • Could you name your own example? 5
  • 6. Examples of One-to-Many Relationship • A Division could have more than one Program offered • A Program could have many students enrolled • Could you name your own example? 6
  • 7. Examples of Many-to-Many Relationship • A student could take many course and a course could have many students • An author could have many books and a book could have many author • A music album could have many artists/performers and an artist/performer could have many albums • Could you name your own example? 7
  • 8. Key in a table • A key in a table is a field or group of fields that creates identity, makes relationship with another table and/or make a table more efficient. 8
  • 9. Primary Key & Foreign • A Primary key is a key that uniquely identifies a row in each table. It is normally denoted with its first two letters, namely, PK. • A Foreign key is a key borrowed from another related table (that’s why its foreign) in order to make the relationship between two tables. It is normally denoted with its first two letters, namely, FK. 9
  • 10. Examples from Premier Database – Primary Key 10 Repnum uniquely identifies the Rep table and is the primary key of this table.
  • 11. Examples from Premier Database – Primary Key 11 Customernum uniquely identifies the Customer table and is the primary key of this table.
  • 12. Examples from Premier Database – Primary Key 12 Ordernum and Partnum makes up the primary key Of the OrderLine table. This is what is known as a Composite Primary key, that is, primary key that is made up of more than one field.
  • 13. Examples from Premier Database • Could you identify any more primary keys from Premier Database? 13
  • 14. Examples from Premier Database – Foreign Key 14 Repnum is a Foreign key borrowed from Rep table
  • 15. Examples from Premier Database • Could you identify any more foreign keys from Premier Database? 15
  • 16. Notation example • One Rep could have one or more customer (one to many) using Primary and foreign key to create the relationship. 16 Customer Customernum (PK) Customername Street City State Zip Balance CreditLimit Repnum (FK) Rep Repnum (PK) Lastname Firstname Street City State Zip Commission Rate 1 M
  • 17. Notation example • Always remember the many side has the Foreign key. In this case the many side is on the Customer table and therefore has the foreign key Repnum which is the primary key of Rep table. 17 Customer Customernum (PK) Customername Street City State Zip Balance CreditLimit Repnum (FK) Rep Repnum (PK) Lastname Firstname Street City State Zip Commission Rate 1 M
  • 18. Examples from Premier Database • Could you identify the different relationship among tables in Premier Database because of the Primary and Foreign keys? 18
  • 19. Referential Integrity • Referential Integrity means that the Foreign key must match in terms of actual values and data types with the related Primary Key. 19
  • 20. Referential Integrity • Example: • The foreign key RepNum in Customer must match with the primary key RepNum in Rep table. 20
  • 21. Referential Integrity • In terms of Data Type • Customer RepNum (Foreign Key) has Text Data type and Rep RepNum (Primary Key) has also Text Data type. 21
  • 22. Seatwork 22 • Colonial and Solmaris • Identify the primary key and foreign keys for each table. Put the name of the table and name its primary key and if there is a foreign key identify the foreign key. • Identify how each table that has the foreign key relates to another table. See slide No. 16 and 17
  • 23. Demo in creating Primary and Foreign Key in MS Access 23
  • 24. Referential Integrity • In terms of actual Values 24
  • 25. Non-Graded Seatwork 25 • Colonial and Solmaris – Check the tables that are related to each other and then check data types for both Foreign and Primary Keys that are related. – Check also the values of the related Primary Keys if you could find it in the related Foreign keys. – Try to enter values in the Foreign Key that could not be found in related table that has the Primary Key. Did MS Access pops out an error message? What does it say?
  • 26. On-your-own Exercise 26 – Imagine we want to make a simple appointment database for a small clinic here in Pohnpei with a fictitious name Health Wealth clinic. And the database would record appointments for Patients with their Doctor on a given date. – Now a Patient could have one or more appointments in Health Wealth clinic to one or more Doctor. – A Doctor could also have one or more appointment with one or more patients every day. – Create a database in MS Access named Keys-Lastname.accdb – Create three tables, namely, Patients, Doctors and Appointments. – Create necessary fields for each table that you think should be there. – Create a Primary Key for each tables. – And create also Foreign keys if necessary to create relationship among tables. – Use the Database Tools to create the Relationship among tables after you created both the Primary Keys and Foreign Keys. – Enter at least 3 doctors, 5 patients and 8 appointments – Send your work to nationalcis@gmail.com with the title Database with Keys activity
  • 27. Summary (continued) • Modern database normally has tables that has logical relationships with one another. • Three primary type of relationships are one-to-one, one-to-many and many-to-many. • Each row/record in a Table should be unique using a Primary Key • To create a relationship among tables you must have the Foreign key on the other table. • Referential Integrity protects the integrity of your data by matching both your Primary key and Foreign in terms of Data types and actual values. 27