Содержание
- 2. The Road Ahead E/R Diagram Introduction to Entity-Relationship (ER) Diagrams Entity Relationship Constraints Subclasses Weak Entity
- 3. A real database may have a large number of tables… Imagine that you are asked to
- 4. Designing a Database for an Application Conceptually model the requirements of the application What are the
- 5. ER Diagram Companies country name Persons addr name Products name category price Buy Employ Make
- 6. ER Diagram Rectangle = Entity Entity = Real-world object (e.g., a bar) Entity Set = Collection
- 7. ER Diagram Oval = Attribute = Property of an entity set Companies country name Persons addr
- 8. ER Diagram Diamond = Relationship = Connection between two entity sets Companies country name Persons addr
- 9. ER Diagram Diamond = Relationship = Connection between two entity sets Persons buy products Persons addr
- 10. ER Diagram Diamond = Relationship = Connection between two entity sets Companies make products Companies country
- 11. Types of Relationships Many-to-Many Relationships Many-to-One Relationships One-to-One Relationships
- 12. Many-to-Many Relationship One person can buy multiple products One product can be bought by multiple persons
- 13. Many-to-One Relationship One company can make multiple products But one product can only be made by
- 14. One-to-One Relationship A city can be the capital of only one country A country can have
- 15. Multi-way Relationships What if we want to record the store from which the person buys the
- 16. From Multi-way to Binary Persons Products Buy Stores Persons Products Buyer of Stores Transactions Product of
- 17. Exercise Each player prefers only one game One player can prefer one game One game can
- 18. Exercise No two shops sell the same product One product can be sold by one shop
- 19. Exercise Any two players are from two different countries One player can be from one country
- 20. One More Thing about Relationships A relationship can have its own attribute Persons addr name Products
- 21. One More Thing about Relationships A relationship can have its own attribute If we want to
- 22. Roles Sometimes an entity set may appear more than once in a relationship Example: some persons
- 23. Roles Question: A relationship connects an entity set to itself, does it have to be one-to-one?
- 24. Roles Question: A relationship connects an entity set to itself, does it have to be one-to-one?
- 25. Roadmap Constraints Subclasses Weak Entity Sets ER Design Principle Translating an ER Diagram into a Relational
- 26. Constraints Some conditions that entity sets and relationships should satisfy We will focus on three types
- 27. Key One or more attributes that are underlined Meaning: They uniquely represent each entity in the
- 28. Key One or more attributes that are underlined Meaning: They uniquely represent each entity in the
- 29. Key One or more attributes that are underlined What now? Each product has a unique combination
- 30. Key Rule: Every entity set should have a key So that we can uniquely refer to
- 31. Referential Integrity One company may make multiple products One product is made by one company Can
- 32. Referential Integrity Products Companies Make One company may make multiple products One product is made by
- 33. Referential Integrity: Exercise A city can be the capital of only one country A country must
- 34. Referential Integrity: Exercise A company must hire at least one person A person must be hired
- 35. Referential Integrity Products Companies Make What if every company should make at least one product? In
- 36. Degree Constraint Each company should make at least 1 product Products Companies Make ≥ 1
- 37. Degree Constraint Each company can make at most 1000 product Note Not required in the exam
- 38. Roadmap Constraints Subclasses Weak Entity Sets ER Design Principle Translating an ER Diagram into a Relational
- 39. Subclass PhDs are a special type of Students Subclass = Special type The connection between a
- 40. Subclass An entity set can have multiple subclasses Example Superclass: Computers Subclass 1: Desktop Subclass 2:
- 41. Weak Entity Sets Weak entity sets are a special type of entity sets that cannot be
- 43. Weak Entity Sets Problem: there are cities with identical names Observation: cities in the same state
- 44. Exercise Consider two entity sets: Players and Teams Each player has a name and a number
- 45. Road Map Design Principle of ER Diagrams Translating an ER Diagram into a Relational Scheme Design
- 46. Design Principle 1: Be Faithful Be faithful to the specifications of the application Capture the requirements
- 47. Design Principle 2: Avoid Redundancy Avoid repetition of information Example Problems that can be caused by
- 48. Design Principle 3: Keep It Simple Each student is mentored by one faculty One faculty can
- 49. Design Principle 3: Keep It Simple Each student is mentored by one faculty One faculty can
- 50. Design Principle 3: Keep It Simple There are four types of students: Year 1, Year 2,
- 51. Design Principle 3: Keep It Simple There are four types of students: Year 1, Year 2,
- 52. Tips: When to Use Subclasses Case 1: When a subclass has some attribute that is absent
- 53. Design Principle 4: Don’t Over-use Weak Entity Sets Too many entity sets that should not be
- 54. Road Map Design Principle of ER Diagrams Translating an ER Diagram into a Relational Scheme Design
- 55. ER Diagram ? Relational Schema Products (name, price) Persons (name, addr) Buy (product_name, person_name) Terminology A
- 56. ER Diagram ? Relational Schema General rules: Each entity set becomes a relation Each many-to-many relationship
- 57. Entity Set ? Relation Each entity set is converted into a relation that contains all its
- 58. Many-to-Many Relationship ? Relation Converted into a relation that contains all keys of the participating entity
- 59. Many-to-Many Relationship ? Relation If an entity is involved multiple times in a relationship Its key
- 60. Weak Entity Set ? Relation Each weak entity set is converted to a relation that contains
- 61. Subclass ? Relation There are three different ways The ER approach The OO approach The NULL
- 62. The ER approach One relation for each entity set Movies( ID, name ) Cartoon( ID, Is_3D
- 63. The OO approach One relation for each entity set and each possible subclass combination Movies( ID,
- 64. The NULL approach One relation that includes everything Movies( ID, name, Is_3D, Is_Adoption ) For non-cartoon
- 65. Which Approach is the Best? It depends The NULL approach Advantage: Needs only one relation Disadvantage:
- 66. ER Diagram ? Relational Schema General rules: Each entity set becomes a relation Each many-to-many relationship
- 67. Many-to-One Relationship ? Relation Intuitive translation: Products( Pname, price ) Companies( Cname, country ) Make( Pname,
- 68. Many-to-One Relationship ? Relation In general, we do not need to create a relation for a
- 69. Many-to-One Relationship ? Relation Only need to put the key of the “one” side into the
- 70. One-to-One Relationship ? Relation No need to create a relation for a one-to-one relationship Only need
- 72. Скачать презентацию