Referential Integrity in Databases
Referential Integrity in Databases
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