210 likes | 292 Views
Relationnel Model. Relational Database. General Concepts. Relation, Attribute, Domain Cartesian product of domains D 1 ,D 2 ,…,D n gives n-uples or tuples {d 1 ,d 2 ,…,d n : d i D i } Relation is a subset of the Cartesian product of a list of domains
E N D
RelationnelModel Bogdan Shishedjiev Relational Model
Relational Database Bogdan Shishedjiev Relational Model
General Concepts • Relation, Attribute, Domain • Cartesian product of domains D1,D2,…,Dn gives n-uples or tuples {d1 ,d2 ,…,dn: di Di} • Relation is a subset of the Cartesian product of a list of domains • The attribute is the column of the relation and it has a name. • Relational Schema (intention), extension (relation) • Relational database Bogdan Shishedjiev Relational Model
Example D1 = {Car, Motor, Wheel, Cylinder Head, Spring, Chassis, Piston, Connecting Rod, Tyre, Wheel Rim}, D2 ={1..8} R(Unit:D1,Part:D1,Quantity:D2) Bogdan Shishedjiev Relational Model
Functional Dependency • Let R(X, Y, Z). There is functional dependency between X and Y or XY if and only if for any values of X,Y and Z – (a,b,c) and (a’,b’,c’) R(a,b,c) and R(a,b’,c’) b=b’ • Key If in R(A1,A2,…,An) X A1,A2,…,An and there is no YX Y A1,A2,…,An . X is a candidate key (superkey) • Primary key Bogdan Shishedjiev Relational Model
Functional Dependency • Axioms (Armstrong) • (R1) Reflexivity : if Y X then X Y • (R2) augmentation : if X Y and W is any set of attributes then XW YW • (R3) transitivity : if X Y and Y Z then X Z • (R4) pseudo-transitivity : if X Y and YW Z then XW Z • (R5) union : if X Y and X Z then X YZ • (R6) decomposition : if X YZ then X Y and X Z Bogdan Shishedjiev Relational Model
Refering relation Refered relation Nonkey attrubute key Integrity Constraints • Entity Integrity • Domain Integrity • Referential Integrity – Foreign key Bogdan Shishedjiev Relational Model
Relational Algebra Notation X – set of attrubutes A(X) – The set of all possible tuples of X L/Y – The restriction of the realization L over the subset Y X X={ PART:D1, SUPPLIER:D2 } Y={PARTD1, PROJECT:D3 } Z={PARTD1, SUPPLIERD2, PROJECTD3 } - D1 = { nut, bolt, screw} - D2 = { Peter, Paul, Mary } - D3 = { a, b, c } Bogdan Shishedjiev Relational Model
Relational Algebra Projection (1) Z = Y (2) YR={LA(Y); $L'A(X), (L'/Y = L) и (L' R) } LetY={ PARTD1, SUPPLIERD2 } Bogdan Shishedjiev Relational Model
Relational Algebra • Selection (1) Y =X (2) ER = { L A(X) / (L R) and (E(L) = true) } E = (CITY=‘london') (BIRTH≤ '31.08.79') ((SPORT='judo') (SPORT='football')) Bogdan Shishedjiev Relational Model
Relational Algebra • Product or Inner Join (1) Z=XY (2) R*S = { LA(Z) that (L/X R) and (L/Y S) } Bogdan Shishedjiev Relational Model
Relational Algebra • Union, Intersection, Difference The schema is identical Bogdan Shishedjiev Relational Model
Relational Algebra • Cartesian Product - XY= (1) Z=XY (2) RS = R*S Bogdan Shishedjiev Relational Model
Relational Algebra • Equi-join Bogdan Shishedjiev Relational Model
Normalization • Good schema • Universal Relation FIRM ( N_employee, N_department, chef, contract_type) HOSPITAL(N_patient, Name, Ward, Doctor) • Update anomaly • Deletion anomaly • Insertion anomaly • Redundancy Bogdan Shishedjiev Relational Model
Decomposition • Decomposition • DefinitionR = R1*R2*R3*…*Rn • Lossless decomposition • Preservation of dependencies Bogdan Shishedjiev Relational Model
Decomposition Bogdan Shishedjiev Relational Model
First Normal Form • Definition – A relation is in 1NM if and only if all underlying domains contain scalar values only and it has no repetitive groups Bogdan Shishedjiev Relational Model
First Normal Form MOVIE(No, Name, Director, Actor1, Actor2, Actor3) Bogdan Shishedjiev Relational Model
Second Normal Form • Definition – A relation is in 2NM if and only if it is in 1NF and no non-prime attribute in the table is functionally dependent on a proper subset of a candidate key (total dependency) • Example • STOCK (part, warehouse, quant, address) is not in2NF • FD : part, warehouse-> quant ; warehouse -> address • Decomposition • STOCK (part, warehouse, quant) • LOCAL(warehouse, address) Bogdan Shishedjiev Relational Model
Third Normal Form • Definition – A relation is in 3NM if and only if it is in 2NF and every nonkey attribute is nontransitively dependent on the primary key • Example PERSONAL(employee, name, FirstName, Service, Address)DF : employee -> name, FirstName, Service, Address; Service -> Address Decomposition PERSONAL(employee, name, FirstName, Service) LOCAL(Service, Address) Bogdan Shishedjiev Relational Model