Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational data integrity 1 Lecture 8 Relational data integrity.

Similar presentations

Presentation on theme: "Relational data integrity 1 Lecture 8 Relational data integrity."— Presentation transcript:

1 Relational data integrity 1 Lecture 8 Relational data integrity

2 2 Outline integrity constraints and data definition candidate keys foreign keys nulls domains conditional expressions normal forms

3 Relational data integrity 3 Constraints in real life systems constraints exist between data values it would be useful to communicate these constraints to the database system data is associated with a meaning stating some constraints on data describing a part of the meaning 90% should be spent on integrity constraints definition

4 Relational data integrity 4 Examples of possible inaccuracies how would you express, in NL, integrity constraints that would avoid the above situations?

5 Relational data integrity 5 Types of integrity constraints integrity constraint application specific integrity constraints examples mechanisms domains conditional expressions normal forms generic (inherent to the relational model - resulting from definitions) entity integrity : primary key referential integrity : foreign key

6 Relational data integrity 6 Data definition integrity constraints definition in a relational language should include primary key definition candidate keys definition foreign key definition - including foreign key rules conditional expressions

7 Relational data integrity 7 Example - SQL data definition (in brief) CREATE @ ) ; ::= PRIMARY KEY ( ) ::= CANDIDATE KEY ( ) ::= FOREIGN KEY ( ) REFERENCES ON DELETE ON UPDATE CREATE ASSERTION CHECK

8 Relational data integrity 8 Candidate key - example

9 Relational data integrity 9 Candidate key candidate key uniqueness property irreducibility property entity integrity constraint simple/composite primary/alternate

10 Relational data integrity 10 Foreign key - example

11 Relational data integrity 11 Foreign key foreign key (FK) corresponding candidate key (CK) in another relation FK CK such that FK = CK (reverse not required) target/referenced relation/tuple | referring relation/tuple referential integrity constraint foreign keys and PostgreSQL

12 Relational data integrity 12 Referential diagram

13 Relational data integrity 13 Foreign key rules - motivation

14 Relational data integrity 14 What happens if... short saving accounts are not offered by the bank anymore? the code and name for small saving accounts is to be changed to i-sav and instant saving respectively? the interest for s-sav is to be decreased by 0.3%?

15 Relational data integrity 15 Foreign key rules the modifications are performed in the REFERRED relation rules ON DELETE RESTRICT ON DELETE CASCADE ON UPDATE RESTRICT ON UPDATE CASCADE split into four groups: think of one example for each situation; dont use the study guide

16 Relational data integrity 16 Examples on delete restrict students and books on delete cascade employees and children on update restrict students and modules on update cascade employees and departments

17 Relational data integrity 17 Nulls

18 Relational data integrity 18 Nulls representing missing/unavailable information primary key and nulls foreign key and nulls

19 Relational data integrity 19 Domains expressing integrity constraints on scalar values constraints on permissible scalar values constraints on the applicability of scalar operators SQL does not support domains offers other mechanisms

20 Relational data integrity 20 Domains - example of integrity constraints

21 Relational data integrity 21 Conditional expressions will be studied with SQL pointer forward: the universitys database: a student has two choose two options (1/2cu courses) in the final year; if the students chooses an extra optional course than the final year project will count as only 1/2cu

22 Relational data integrity 22 FDs, MDs, and JDs particular constraints functional dependencies multiple dependencies join dependencies expressed by means of normal forms extensively studied in the following lectures

23 Relational data integrity 23 Normal forms - example

24 Relational data integrity 24 Integrity constraints - further considerations state and transition integrity constraints example when and how are the integrity constraints applied depends on the type normal forms and domains - always entity and referential - after each transaction conditional expressions –default : after each transaction –other possibilities? correct database = the logical AND of the set of integrity constraints is satisfied after each transaction

25 Relational data integrity 25 Summary the relational data model data objects operators integrity constraints SQL implements the relational model the subject of the next lectures you know what a relational model is, but do not know yet how to design one

Download ppt "Relational data integrity 1 Lecture 8 Relational data integrity."

Similar presentations

Ads by Google