Database Systems - Database Design

1,857 views
1,741 views

Published on

Normalization, normal forms, entity/relationship model.

Published in: Education, Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,857
On SlideShare
0
From Embeds
0
Number of Embeds
185
Actions
Shares
0
Downloads
194
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Database Systems - Database Design

  1. 1. Normalization Entity/Relationship Model Database Systems Database Design H. Turgut Uyar ¸Sule ¨O˘g¨ud¨uc¨u 2002-2015 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  2. 2. Normalization Entity/Relationship Model License c 2002-2015 T. Uyar, ¸S. ¨O˘g¨ud¨uc¨u You are free to: Share – copy and redistribute the material in any medium or format Adapt – remix, transform, and build upon the material Under the following terms: Attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. NonCommercial – You may not use the material for commercial purposes. ShareAlike – If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. For more information: https://creativecommons.org/licenses/by-nc-sa/4.0/ Read the full license: https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  3. 3. Normalization Entity/Relationship Model Topics 1 Normalization Introduction Normal Forms 3rd Normal Form Views 2 Entity/Relationship Model Introduction E/R Diagrams H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  4. 4. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Topics 1 Normalization Introduction Normal Forms 3rd Normal Form Views 2 Entity/Relationship Model Introduction E/R Diagrams H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  5. 5. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Functional Dependency let Z be the set of all attributes of the relation R let A, B ⊆ Z A functionally determines B: A → B for every A value there can only be one B value every functional dependency is an integrity constraint H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  6. 6. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Functional Dependency let Z be the set of all attributes of the relation R let A, B ⊆ Z A functionally determines B: A → B for every A value there can only be one B value every functional dependency is an integrity constraint H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  7. 7. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Example Relation R MOVIEID TITLE COU LANG ACTORID NAME ORD 6 The Usual Suspects UK EN 308 Gabriel Byrne 2 228 Ed Wood US EN 26 Johnny Depp 1 70 Being John Malkovich US EN 282 Cameron Diaz 2 1512 Suspiria IT IT 745 Udo Kier 9 70 Being John Malkovich US EN 503 John Malkovich 14 assumption: the language of the movie is the language of the country where it was made H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  8. 8. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Example Relation R MOVIEID TITLE COU LANG ACTORID NAME ORD 6 The Usual Suspects UK EN 308 Gabriel Byrne 2 228 Ed Wood US EN 26 Johnny Depp 1 70 Being John Malkovich US EN 282 Cameron Diaz 2 1512 Suspiria IT IT 745 Udo Kier 9 70 Being John Malkovich US EN 503 John Malkovich 14 assumption: the language of the movie is the language of the country where it was made H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  9. 9. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Functional Dependency Examples MOVIEID → TITLE MOVIEID → {TITLE, COUNTRY, LANGUAGE} ACTORID → NAME {MOVIEID, ACTORID} → ORD trivial: MOVIEID → MOVIEID redundant: {MOVIEID, ACTORID} → COUNTRY H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  10. 10. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Functional Dependency Examples MOVIEID → TITLE MOVIEID → {TITLE, COUNTRY, LANGUAGE} ACTORID → NAME {MOVIEID, ACTORID} → ORD trivial: MOVIEID → MOVIEID redundant: {MOVIEID, ACTORID} → COUNTRY H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  11. 11. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Irreducible Set let S be the set of all FDs of the relation let T ⊆ S T is an irreducible set of FDs if: T contains as few elements as possible, and every FD in S can be derived from the FDs in T let there be only one attribute on the right hand side of FDs H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  12. 12. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Irreducible Set let S be the set of all FDs of the relation let T ⊆ S T is an irreducible set of FDs if: T contains as few elements as possible, and every FD in S can be derived from the FDs in T let there be only one attribute on the right hand side of FDs H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  13. 13. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Irreducible Set Example MOVIEID → TITLE MOVIEID → COUNTRY COUNTRY → LANGUAGE ACTORID → NAME {MOVIEID, ACTORID} → ORD H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  14. 14. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Dependency Example H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  15. 15. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Topics 1 Normalization Introduction Normal Forms 3rd Normal Form Views 2 Entity/Relationship Model Introduction E/R Diagrams H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  16. 16. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Normal Forms normal form: set of conditions that relations must satisfy 1NF, 2NF, 3NF, BCNF, 4NF, 5NF every form adds stricter conditions to the previous form NF of database = NF of weakest relation 1NF: attribute values have to be atomic simplifying assumption for definitions: A TABLE HAS ONLY ONE CANDIDATE KEY, WHICH IS ALSO THE PRIMARY KEY. H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  17. 17. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Normal Forms normal form: set of conditions that relations must satisfy 1NF, 2NF, 3NF, BCNF, 4NF, 5NF every form adds stricter conditions to the previous form NF of database = NF of weakest relation 1NF: attribute values have to be atomic simplifying assumption for definitions: A TABLE HAS ONLY ONE CANDIDATE KEY, WHICH IS ALSO THE PRIMARY KEY. H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  18. 18. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Normal Forms normal form: set of conditions that relations must satisfy 1NF, 2NF, 3NF, BCNF, 4NF, 5NF every form adds stricter conditions to the previous form NF of database = NF of weakest relation 1NF: attribute values have to be atomic simplifying assumption for definitions: A TABLE HAS ONLY ONE CANDIDATE KEY, WHICH IS ALSO THE PRIMARY KEY. H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  19. 19. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Normalization normalization: transforming relations from one form to the next, stricter form transformation must be lossless Theorem (Heath) let Z be the set of all attributes of the relation R let A, B, C ⊆ Z A → B ⇒ R = (A, B) join (A, C) H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  20. 20. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Normalization normalization: transforming relations from one form to the next, stricter form transformation must be lossless Theorem (Heath) let Z be the set of all attributes of the relation R let A, B, C ⊆ Z A → B ⇒ R = (A, B) join (A, C) H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  21. 21. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Lossless Transition Example R1 MOVIEID TITLE COU LANG 6 The Usual Suspects UK EN 228 Ed Wood US EN 70 Being John Malkovich US EN 1512 Suspiria IT IT R2 MOVIEID ACTORID NAME ORD 6 308 Gabriel Byrne 2 228 26 Johnny Depp 1 70 282 Cameron Diaz 2 1512 745 Udo Kier 9 70 503 John Malkovich 14 R = R1 join R2 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  22. 22. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Lossy Transition Example R1 MOVIEID TITLE COU LANG 6 The Usual Suspects UK EN 228 Ed Wood US EN 70 Being John Malkovich US EN 1512 Suspiria IT IT R2 COU ACTORID NAME ORD UK 308 Gabriel Byrne 2 US 26 Johnny Depp 1 US 282 Cameron Diaz 2 IT 745 Udo Kier 9 US 503 John Malkovich 14 R = R1 join R2 {MOVIEID, ACTORID} → ORD H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  23. 23. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Lossy Transition Example R1 MOVIEID TITLE COU LANG 6 The Usual Suspects UK EN 228 Ed Wood US EN 70 Being John Malkovich US EN 1512 Suspiria IT IT R2 COU ACTORID NAME ORD UK 308 Gabriel Byrne 2 US 26 Johnny Depp 1 US 282 Cameron Diaz 2 IT 745 Udo Kier 9 US 503 John Malkovich 14 R = R1 join R2 {MOVIEID, ACTORID} → ORD H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  24. 24. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Anomalies insert: data is known but can not be inserted delete: deleting some data causes some other data to be lost update: updating data requires modifications in multiple tuples H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  25. 25. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Anomaly Examples example database the country of the movie“Gattaca”is known to be US, but this cannot be inserted if there is no actor in the movie deleting that Johnny Depp acts in the movie“Ed Wood” also deletes that the movie was made in the US changing the country of the movie“Being John Malkovich” requires modifications in two tuples H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  26. 26. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Anomaly Examples example database the country of the movie“Gattaca”is known to be US, but this cannot be inserted if there is no actor in the movie deleting that Johnny Depp acts in the movie“Ed Wood” also deletes that the movie was made in the US changing the country of the movie“Being John Malkovich” requires modifications in two tuples H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  27. 27. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Anomaly Examples example database the country of the movie“Gattaca”is known to be US, but this cannot be inserted if there is no actor in the movie deleting that Johnny Depp acts in the movie“Ed Wood” also deletes that the movie was made in the US changing the country of the movie“Being John Malkovich” requires modifications in two tuples H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  28. 28. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2nd Normal Form 2NF: every non-key attribute depends on the primary key in a relation R that conforms to 1NF, if: R(A, B, C, D), primary key: (A, B), and A → D to transform to 2NF, divide into: R1(A, D), primary key: A, and R2(A, B, C), primary key: (A, B), where A is a foreign key referencing R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  29. 29. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2nd Normal Form 2NF: every non-key attribute depends on the primary key in a relation R that conforms to 1NF, if: R(A, B, C, D), primary key: (A, B), and A → D to transform to 2NF, divide into: R1(A, D), primary key: A, and R2(A, B, C), primary key: (A, B), where A is a foreign key referencing R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  30. 30. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 1NF-2NF Transition Example among non-key attributes, only ORD depends on primary key A: {MOVIEID} B: {ACTORID} C: {NAME, ORD} D: {TITLE, COUNTRY, LANGUAGE} R1(MOVIEID, TITLE, COUNTRY, LANGUAGE) primary key: MOVIEID R2(MOVIEID, ACTORID, NAME, ORD) primary key: {MOVIEID, ACTORID} MOVIEID is a foreign key referencing R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  31. 31. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 1NF-2NF Transition Example among non-key attributes, only ORD depends on primary key A: {MOVIEID} B: {ACTORID} C: {NAME, ORD} D: {TITLE, COUNTRY, LANGUAGE} R1(MOVIEID, TITLE, COUNTRY, LANGUAGE) primary key: MOVIEID R2(MOVIEID, ACTORID, NAME, ORD) primary key: {MOVIEID, ACTORID} MOVIEID is a foreign key referencing R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  32. 32. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 1NF-2NF Transition Example R2 still not 2NF: ACTORID → NAME A: {ACTORID} B: {MOVIEID} C: {ORD} D: {NAME} R3(ACTORID, NAME) primary key: ACTORID R4(MOVIEID, ACTORID, ORD) primary key: {MOVIEID, ACTORID} ACTORID is a foreign key referencing R3 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  33. 33. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 1NF-2NF Transition Example R2 still not 2NF: ACTORID → NAME A: {ACTORID} B: {MOVIEID} C: {ORD} D: {NAME} R3(ACTORID, NAME) primary key: ACTORID R4(MOVIEID, ACTORID, ORD) primary key: {MOVIEID, ACTORID} ACTORID is a foreign key referencing R3 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  34. 34. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF Relation Examples R1 MOVIEID TITLE COU LANG 6 The Usual Suspects UK EN 228 Ed Wood US EN 70 Being John Malkovich US EN 1512 Suspiria IT IT R3 ACTORID NAME 308 Gabriel Byrne 26 Johnny Depp 282 Cameron Diaz 745 Udo Kier 503 John Malkovich R4 MOVIEID ACTORID ORD 6 308 2 228 26 1 70 282 2 1512 745 9 70 503 14 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  35. 35. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Dependency Example H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  36. 36. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF Corrected Anomalies example database if the country of the movie“Gattaca”is known to be US, this can be inserted to R1 if Johnny Depp is deleted from the movie“Ed Wood”, the country of the movie is still kept in R1 changing the country of the movie“Being John Malkovich” requires updating only one tuple in R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  37. 37. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF Corrected Anomalies example database if the country of the movie“Gattaca”is known to be US, this can be inserted to R1 if Johnny Depp is deleted from the movie“Ed Wood”, the country of the movie is still kept in R1 changing the country of the movie“Being John Malkovich” requires updating only one tuple in R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  38. 38. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF Corrected Anomalies example database if the country of the movie“Gattaca”is known to be US, this can be inserted to R1 if Johnny Depp is deleted from the movie“Ed Wood”, the country of the movie is still kept in R1 changing the country of the movie“Being John Malkovich” requires updating only one tuple in R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  39. 39. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF Remaining Anomalies example database it is known that movies made in Brazil are in Portuguese but this can not be inserted if there is no movie made in Brazil deleting the movie“Suspiria”also deletes that the language of movies made in Italy is Italian changing the language of the movies made in the US requires two tuples to be updated H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  40. 40. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF Remaining Anomalies example database it is known that movies made in Brazil are in Portuguese but this can not be inserted if there is no movie made in Brazil deleting the movie“Suspiria”also deletes that the language of movies made in Italy is Italian changing the language of the movies made in the US requires two tuples to be updated H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  41. 41. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF Remaining Anomalies example database it is known that movies made in Brazil are in Portuguese but this can not be inserted if there is no movie made in Brazil deleting the movie“Suspiria”also deletes that the language of movies made in Italy is Italian changing the language of the movies made in the US requires two tuples to be updated H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  42. 42. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Topics 1 Normalization Introduction Normal Forms 3rd Normal Form Views 2 Entity/Relationship Model Introduction E/R Diagrams H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  43. 43. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 3rd Normal Form 3NF: non-key attributes do not depend on any attributes other than the primary key in a relation R that conforms to 2NF, if: R(A, B, C, D), primary key: A, and C → D to transform to 3NF, divide into: R1(C, D), primary key: C, and R2(A, B, C), primary key: A, where C is a foreign key referencing R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  44. 44. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 3rd Normal Form 3NF: non-key attributes do not depend on any attributes other than the primary key in a relation R that conforms to 2NF, if: R(A, B, C, D), primary key: A, and C → D to transform to 3NF, divide into: R1(C, D), primary key: C, and R2(A, B, C), primary key: A, where C is a foreign key referencing R1 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  45. 45. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF-3NF Transition Example R1: COUNTRY → LANGUAGE A: {MOVIEID} B: {TITLE} C: {COUNTRY} D: {LANGUAGE} R5(COUNTRY, LANGUAGE) primary key: COUNTRY R6(MOVIEID, TITLE, COUNTRY) primary key: MOVIEID COUNTRY is a foreign key referencing R5 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  46. 46. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 2NF-3NF Transition Example R1: COUNTRY → LANGUAGE A: {MOVIEID} B: {TITLE} C: {COUNTRY} D: {LANGUAGE} R5(COUNTRY, LANGUAGE) primary key: COUNTRY R6(MOVIEID, TITLE, COUNTRY) primary key: MOVIEID COUNTRY is a foreign key referencing R5 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  47. 47. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 3NF Relation Examples R6 MOVIEID TITLE COU 6 The Usual Suspects UK 228 Ed Wood US 70 Being John Malkovich US 1512 Suspiria IT R5 COU LANG UK EN US EN IT IT R3 ACTORID NAME 308 Gabriel Byrne 26 Johnny Depp 282 Cameron Diaz 745 Udo Kier 503 John Malkovich R4 MOVIEID ACTORID ORD 6 308 2 228 26 1 70 282 2 1512 745 9 70 503 14 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  48. 48. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Dependency Example H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  49. 49. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 3NF Corrected Anomalies example database if movies made in Brazil are in known to be in Portuguese, this can be inserted into R5 if the movie ”Suspiria”is deleted, R5 still keeps that movies made in Italy are in Italian changing the language of the movies made in the US requires modifying only one tuple in R5 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  50. 50. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 3NF Corrected Anomalies example database if movies made in Brazil are in known to be in Portuguese, this can be inserted into R5 if the movie ”Suspiria”is deleted, R5 still keeps that movies made in Italy are in Italian changing the language of the movies made in the US requires modifying only one tuple in R5 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  51. 51. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References 3NF Corrected Anomalies example database if movies made in Brazil are in known to be in Portuguese, this can be inserted into R5 if the movie ”Suspiria”is deleted, R5 still keeps that movies made in Italy are in Italian changing the language of the movies made in the US requires modifying only one tuple in R5 H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  52. 52. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Boyce-Codd Normal Form BCNF: all functional dependencies must be on candidate keys consider dependencies between key attributes H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  53. 53. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References BCNF Example example database let movie titles be unique candidate keys: {MOVIEID, ACTORID} {TITLE, ACTORID} non-conforming functional dependencies: MOVIEID → TITLE TITLE → MOVIEID H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  54. 54. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References BCNF Example example database let movie titles be unique candidate keys: {MOVIEID, ACTORID} {TITLE, ACTORID} non-conforming functional dependencies: MOVIEID → TITLE TITLE → MOVIEID H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  55. 55. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Topics 1 Normalization Introduction Normal Forms 3rd Normal Form Views 2 Entity/Relationship Model Introduction E/R Diagrams H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  56. 56. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Views presenting a derived table like a base table: view isolating users and application programs from changes in database structure creating a view: CREATE VIEW view_name AS SELECT ... SELECT will be executed every time the view is used H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  57. 57. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Views presenting a derived table like a base table: view isolating users and application programs from changes in database structure creating a view: CREATE VIEW view_name AS SELECT ... SELECT will be executed every time the view is used H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  58. 58. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References View Example identifiers, titles and years of new movies CREATE VIEW NEW_MOVIE AS SELECT ID, TITLE, YR FROM MOVIE WHERE (YR > 1995) SELECT * FROM NEW_MOVIE H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  59. 59. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Updating Views any change will have to performed on the base tables rules need to be defined creating a rule: CREATE RULE rule_name AS ON event TO view_name [ WHERE condition ] DO [ INSTEAD ] sql_statement H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  60. 60. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References Updating Views any change will have to performed on the base tables rules need to be defined creating a rule: CREATE RULE rule_name AS ON event TO view_name [ WHERE condition ] DO [ INSTEAD ] sql_statement H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  61. 61. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References View Rule Example modify the title of a new movie UPDATE NEW_MOVIE SET TITLE = ... WHERE (ID = ...) rule for updating the base table CREATE RULE UPDATE_TITLE AS ON UPDATE TO NEW_MOVIE DO INSTEAD UPDATE MOVIE SET TITLE = new.TITLE WHERE (ID = old.ID) H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  62. 62. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References View Rule Example modify the title of a new movie UPDATE NEW_MOVIE SET TITLE = ... WHERE (ID = ...) rule for updating the base table CREATE RULE UPDATE_TITLE AS ON UPDATE TO NEW_MOVIE DO INSTEAD UPDATE MOVIE SET TITLE = new.TITLE WHERE (ID = old.ID) H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  63. 63. Normalization Entity/Relationship Model Introduction Normal Forms 3rd Normal Form Views References References Required Reading: Date Chapter 11: Functional Dependencies Chapter 12: Further Normalization I: 1NF, 2NF, 3NF, BCNF Chapter 10: Views H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  64. 64. Normalization Entity/Relationship Model Introduction E/R Diagrams References Topics 1 Normalization Introduction Normal Forms 3rd Normal Form Views 2 Entity/Relationship Model Introduction E/R Diagrams H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  65. 65. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity/Relationship Model modeling approach (Chen 1976) entities properties relationships H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  66. 66. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entities entity: set of“things”with the same attributes elements of the set are instances of the entity strong: can exist by itself weak: existence depends on other entities H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  67. 67. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity Examples entity: movie, person person instance: Johnny Depp strong entity: person weak entity: movie H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  68. 68. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity Examples entity: movie, person person instance: Johnny Depp strong entity: person weak entity: movie H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  69. 69. Normalization Entity/Relationship Model Introduction E/R Diagrams References Properties property: data describing entity simple / composite key single / multiple valued empty base / derived H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  70. 70. Normalization Entity/Relationship Model Introduction E/R Diagrams References Property Examples property: title, country, language simple: first name, last name composite: full name base: date of birth derived: age H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  71. 71. Normalization Entity/Relationship Model Introduction E/R Diagrams References Property Examples property: title, country, language simple: first name, last name composite: full name base: date of birth derived: age H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  72. 72. Normalization Entity/Relationship Model Introduction E/R Diagrams References Property Examples property: title, country, language simple: first name, last name composite: full name base: date of birth derived: age H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  73. 73. Normalization Entity/Relationship Model Introduction E/R Diagrams References Relationships relationship: connection between entities participant: entities in the relationship degree: number of participants total: all instances of the entity participate in the relationship (otherwise partial) H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  74. 74. Normalization Entity/Relationship Model Introduction E/R Diagrams References Relationship Types one-to-one e.g. capital city relationship between countries and cities one-to-many e.g. management relationship between employees and projects many-to-many e.g. enrollment relationship between students and courses H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  75. 75. Normalization Entity/Relationship Model Introduction E/R Diagrams References Relationship Types one-to-one e.g. capital city relationship between countries and cities one-to-many e.g. management relationship between employees and projects many-to-many e.g. enrollment relationship between students and courses H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  76. 76. Normalization Entity/Relationship Model Introduction E/R Diagrams References Relationship Types one-to-one e.g. capital city relationship between countries and cities one-to-many e.g. management relationship between employees and projects many-to-many e.g. enrollment relationship between students and courses H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  77. 77. Normalization Entity/Relationship Model Introduction E/R Diagrams References Topics 1 Normalization Introduction Normal Forms 3rd Normal Form Views 2 Entity/Relationship Model Introduction E/R Diagrams H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  78. 78. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity/Relationship Diagrams entity: box weak: double lines property: circle composite: sub-circles relationship: diamond between weak and strong: double lines total: connection double lines 1 or n depending on the type of the relationship H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  79. 79. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity/Relationship Diagrams entity: box weak: double lines property: circle composite: sub-circles relationship: diamond between weak and strong: double lines total: connection double lines 1 or n depending on the type of the relationship H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  80. 80. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity/Relationship Diagrams entity: box weak: double lines property: circle composite: sub-circles relationship: diamond between weak and strong: double lines total: connection double lines 1 or n depending on the type of the relationship H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  81. 81. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity/Relationship Diagram Example H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  82. 82. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity/Relationship Diagrams properties excluded if diagram too large alternative representation for relationship: line name of relationship above the line fork at the end of line if“many” circle at the end of line: empty if partial, filled if total no many-to-many relationships add an entity and use two one-to-many relationships H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  83. 83. Normalization Entity/Relationship Model Introduction E/R Diagrams References Entity/Relationship Diagram Example H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  84. 84. Normalization Entity/Relationship Model Introduction E/R Diagrams References Applying to Design every entity is a relation every property is an attribute every one-to-many relationship is a foreign key from the“many”side to the“one”side every many-to-many relationship is a relation with foreign keys to participating entities H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  85. 85. Normalization Entity/Relationship Model Introduction E/R Diagrams References Applying to Design every entity is a relation every property is an attribute every one-to-many relationship is a foreign key from the“many”side to the“one”side every many-to-many relationship is a relation with foreign keys to participating entities H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  86. 86. Normalization Entity/Relationship Model Introduction E/R Diagrams References Applying to Design every entity is a relation every property is an attribute every one-to-many relationship is a foreign key from the“many”side to the“one”side every many-to-many relationship is a relation with foreign keys to participating entities H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems
  87. 87. Normalization Entity/Relationship Model Introduction E/R Diagrams References References Required Reading: Date Chapter 14: Semantic Modeling H. Turgut Uyar, ¸Sule ¨O˘g¨ud¨uc¨u Database Systems

×