Escolar Documentos
Profissional Documentos
Cultura Documentos
• Reminders:
• A foreign key links a child table to its parent
table.
• If a foreign key is non-null, it must match an
existing row in the parent table.
• So... SQL has more keywords for this:
CREATE TABLE PropertyForRent (...
StaffNo VARCHAR(5) NOT NULL,
FOREIGN KEY (StaffNo) REFERENCES Staff);
• SQL will reject operations that would violate
referential integrity
Dept. of Computing Science, University of Aberdeen 11
Referential Integrity
and Referential Actions
• Question: if a key attribute in the parent table is modified,
what should happen in the child table ? - SQL provides 4
alternative referential actions:
• ON UPDATE & ON DELETE specify referential actions which
determines what happens when an attempt to UPDATE or
DELETE a candidate key in a parent table which has matching
rows in child table:
FOREIGN KEY (Key) REFERENCES Table [ON DELETE | UPDATE
Action]
– CASCADE - apply changes to child rows (could trickle down)
– SET NULL - set child keys to NULL
– SET DEFAULT - set child keys to DEFAULT value
– NO ACTION - reject the operation (default)
• Suppose a client is removed from the DreamHome DBMS.
What's the most appropriate action to specify for ClientNo
(primary key) in the Viewing table?