2Outline integrity constraints and data definition candidate keys foreign keysnullsdomainsconditional expressionsnormal forms
3Constraints in real life systems constraints exist between data values it would be useful to communicate these constraints to the database systemdata is associated with a meaningstating some constraints on data describing a part of the meaning90% should be spent on integrity constraints definition
4Examples of possible inaccuracies how would you express, in NL, integrity constraintsthat would avoid the above situations?
5Types of integrity constraints application specific integrity constraintsexamplesmechanismsdomainsconditional expressionsnormal formsgeneric (inherent to the relational model - resulting from definitions)entity integrity : primary keyreferential integrity : foreign key
6Data definitionintegrity constraints definition in a relational language should includeprimary key definitioncandidate keys definitionforeign key definition - including foreign key rulesconditional expressions
11Foreign 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/tuplereferential integrity constraintforeign keys and PostgreSQL
14What 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%?
15Foreign key rulesthe modifications are performed in the REFERRED relationrulesON DELETE RESTRICTON DELETE CASCADEON UPDATE RESTRICTON UPDATE CASCADEsplit into four groups: think of one example for each situation; don’t use the study guide
16Examples on delete restrict on delete cascade on update restrict students and bookson delete cascadeemployees and childrenon update restrictstudents and moduleson update cascadeemployees and departments
18Nulls representing missing/unavailable information primary key and nullsforeign key and nulls
19Domains expressing integrity constraints on scalar values SQL constraints on permissible scalar valuesconstraints on the applicability of scalar operatorsSQLdoes not support domainsoffers other mechanisms
21Conditional expressions will be studied with SQLpointer forward:the university’s 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”
22FDs, MDs, and JDs particular constraints functional dependenciesmultiple dependenciesjoin dependenciesexpressed by means of normal formsextensively studied in the following lectures
24Integrity constraints - further considerations state and transition integrity constraintsexamplewhen and how are the integrity constraints applieddepends on the type‘normal forms’ and ‘domains’ - alwaysentity and referential - after each transactionconditional expressionsdefault : after each transactionother possibilities?correct database = the logical AND of the set of integrity constraints is satisfied after each transaction
25Summary the relational data model SQL implements the relational model data objectsoperatorsintegrity constraintsSQL implements the relational modelthe subject of the next lecturesyou know what a relational model is, but do not know yet how to design one