0% found this document useful (0 votes)
44 views

Referential Integrity in Databases

This document discusses referential integrity in relational databases. It provides examples of think-pair-share activities and scenarios involving a sample student-course database to help students learn about writing SQL statements and validating data manipulation language (DML) statements based on an entity relationship diagram (ERD) and referential integrity constraints. Students are asked to reason through scenarios like whether a teacher can teach multiple subjects, what data needs to be present to insert a new mark, if a student can be in multiple groups, and how to delete data while avoiding referential integrity violations.

Uploaded by

Ferry Kemperman
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Referential Integrity in Databases

This document discusses referential integrity in relational databases. It provides examples of think-pair-share activities and scenarios involving a sample student-course database to help students learn about writing SQL statements and validating data manipulation language (DML) statements based on an entity relationship diagram (ERD) and referential integrity constraints. Students are asked to reason through scenarios like whether a teacher can teach multiple subjects, what data needs to be present to insert a new mark, if a student can be in multiple groups, and how to delete data while avoiding referential integrity violations.

Uploaded by

Ferry Kemperman
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Referential integrity in

relational databases

Ferry Kemperman
Nanjing Foreign Language School
November 2019
Objectives
• You are able to write SQL Select statements based on an information need
• You are able to write simple DML statements based on a given scenario
(Insert/Delete/Update)
• You are able to validate DML statements based on a given ERD
• You are able to validate scenarios using referential integrity constraints
(PK/FK) and apply given cardinalities.
Think-Pair-Share activity
ERD / Populated dataset supplied on paper
2 students together with mini whiteboard.
Teacher shows realistic DML scenario on beamer.
You THINK (by yourself, write down answer in your notebook) about the validity of
this scenario according to ERD design and referential integrity checks.
You PAIR (discuss/whisper) with your partner on your thoughts and write your
agreed answer on the mini whiteboard.
You SHARE your solution with your classmates by holding up the mini whiteboard.
Students comment on each others solution and give their reasoning.
Some scenarios require you to come to the board and share your answer.
Listen carefully to each other to hear the reasoning !
MARKS
MarkId Student_ID Subject_ID Date Mark
100 1 10 2019- 7
Write the following queries.
04-01
101 1 10 2019- 6
04-2 1. Display all students first and last names.
102 2 11 2019- 2
04-3
2. Display all subjects titles in alphabetically ordered
3. Display firstname of students with lastname Hu
STUDENTS 4. Insert the following student into the student table:
Student_ID FirstName LastName Group_ID Student ID 4, Kevin Gu, in group 2
1 George Zhang 1 5. List all marks by student 1
2 Alex Hu 1
3 Tonia Zhu 2 6. List all marks by student Zhang
7. Delete student Tonia from the database
SUBJECT 8. Update student Kevin Gu by changing his group
Subject_ID Title from 2 to 1.
10 Computer Science 9. Reason your answer: Did any student get 6 or
11 Mathematics
12 History higher for mathematics?
10. List all the students that took Computer
GROUP Science.
Group_ID Name
1 AS 1
2 AS 2
Let’s have a look at the example database we used in the SQL business case…once again!
Scenario 1

Can a teacher teach multiple subjects?


Scenario 2

If you want to enter a new mark,


which entities should be present first?
Scenario 3

If Mr.K is teaching CS to Tonia, can


he also teach math to her?
Scenario 4

Can a student be in multiple groups?


Scenario 5

Add Kevin Gu as student, as Mr.K.


as teacher and enroll Kevin in Mr.K’s
CS class. How many records need to be
made in total?
Scenario 6

When can you delete a teacher from


the database? What is the pre-condition?
Scenario 7

Can you assign a new teacher to


a course with one UPDATE statement?
Scenario 8

Why is the subject_ID not stored in the


Teacher table?
Scenario 9

Write a DML statement (Insert)


Tonia’s Math grade, a 7.
Scenario 10 : Bonus

Write a DML statement to delete George


from the database without the DBMS
returning a referential integrity violation!
Sc

You might also like