Relational Model
Relational Model
Objectives
E.g;
Delete tuples :
DELETE
FROM Student
WHERE name=‘Smith’;
Modify the column values in an existing row
UPDATE Students S
SET S.age=S.age +1, S.gpa=S.gpa-1
WHERE S.sid= 53688;
Keys On Relations
Avoids data entry errors
Candidate
A super key without unnecessary attributes
Key
10
Integrity Constraints
13
14
1. Default is NO ACTION
delete/update is rejected
2. CASCADE
also delete all tuples that refer to deleted tuple
3. SET NULL
sets foreign key value of referencing tuple
15
4. SET DEFAULT
sets foreign key value of referencing tuple
Faculty of Information Science
Integrity Constraints over Relations
16
General Constraints
very useful in preventing data entry errors.
E.g student ages be within a certain range of
values; given such an IC specification,
DBMS rejects inserts and updates that violate
the constraint.
illegal instance
legal instance
17
E.g;
Introduction to View
A view is a relation whose rows are not explicitly
stored in the database but are computed as needed
from a view definition
A view is a virtual table based on a SELECT query.
The tables on which the view is based are called
base tables.
Syntax: CREATE VIEW View-name
AS <SELECT Query Expression>
23
24
WHERE S.sid = E.studid AND E.grade = ‘B’;
Update On View
25
FROM Students S
27
No violation happened because the view include a key value for
28
29