table relationships rdbm. prof. leighton2 establishing table relationships rdbms allow us to...
TRANSCRIPT
![Page 1: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/1.jpg)
Table Relationships
RDBM
![Page 2: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/2.jpg)
Prof. Leighton 2
Establishing Table Relationships
• RDBMS allow us to establish relationships among tables
• Have a primary key in our REGIONS table and a foreign key in the STATE table
• Must link or join tables
![Page 3: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/3.jpg)
Prof. Leighton 3
Three Types of Table Relationships
• One to one relationship
• One to many relationship
• Many to many relationship
![Page 4: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/4.jpg)
Prof. Leighton 4
One to One Relationship
• Each record in one table has exactly one matching record in another table• Choose one table as the primary table with the primary key
• Split the REGIONS table into two tables• Table one: physical characteristics of the region such as the area
• Table two: information about home ownership rates
• Have the same number of records in each table• Tables share a one to one relationship
• But they contain different fields
![Page 5: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/5.jpg)
Prof. Leighton 5
One to Many Relationship • REGIONS table contains a primary key,
Region ID• STATES table has foreign key,Region ID
• One record in the first table (the REGION table) matches many records in the second table (the STATES table)
• One record in the STATES table matches only one record in the REGIONS table
• If you join the two tables you will have as many records as you have in the table with the foreign key, the many side of the relationship
• Many may mean zero or only one. (For example, one employer could have advertised none or only one job.)
![Page 6: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/6.jpg)
Prof. Leighton 6
One to Many Relationship, Cont..
• The one table, the table with the primary key, is the primary table
• The many table or the table with the foreign key is the related table
![Page 7: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/7.jpg)
Prof. Leighton 7
Many to Many Relationship• One record in the first table matches many
records in the second table
• One record in the second table matches many records in the first
• These situations are handled by creating a number of one to many relationships• Example: registration at a university
• Many classes and many students
![Page 8: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/8.jpg)
![Page 9: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/9.jpg)
Establishing the Relationship
![Page 10: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/10.jpg)
The Relationship
![Page 11: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/11.jpg)
Prof. Leighton 11
Referential Integrity - Internal Consistency
• Can’t accidentally delete or change related data
• System of rules to ensure relationships between related tables are valid• Can’t enter a value in the foreign key field (related table) that doesn’t
exist in the primary key (primary table)
• Can’t delete record from a primary table if there are matching records in a related table
• Can’t change a primary key value in primary table if that record has related records
• Enforce referential integrity is an option
![Page 12: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/12.jpg)
Prof. Leighton 12
Override Referential Integrity
• Set referential integrity on
• Override• Cascade deletes - when you delete a record from a primary table, Access
automatically deletes from all related tables those records with a foreign key value equal to the primary key value you deleted
• Cascade updates - when you change a primary key value, Access automatically changes all related tables’ foreign key values that equal the primary key value
![Page 13: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/13.jpg)
Override Referential Integrity
![Page 14: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/14.jpg)
Print the Relationship
![Page 15: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/15.jpg)
Print the Relationship
![Page 16: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/16.jpg)
![Page 17: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/17.jpg)
![Page 18: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/18.jpg)
![Page 19: Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in](https://reader035.vdocuments.net/reader035/viewer/2022062417/5519b1cc55034667578b4612/html5/thumbnails/19.jpg)
The End