Download presentation
Presentation is loading. Please wait.
Published byJulia Anderson Modified over 9 years ago
1
COMP 430 Intro. to Database Systems Entity-Relationship Diagram Basics Slides use ideas from Chris Ré.
2
Goal: Agree on DB structure to implement. What entities to model How entities related What constraints exist in domain How to achieve good design
3
(Logical) Entity-Relationship Diagrams Makes Product name category price Company name Precise enough for technical decisions Abstracted enough to omit some implementation details Abstracted enough for non-technical people “The Entity-Relationship model – toward a unified view of data” Peter Chen, 1976
4
Makes Product name category price Company name Entity sets – classes/types of objects Attributes of entity sets Entities – individual objects Relationship – between entity sets Primary key – minimal set of attributes that uniquely identifies entity
5
Makes Buys Employs Product namecategory price Person address namessn Company stockprice name
6
Mathematical definitions 1 2 3 a b c d AB Sets A, B: A={1,2,3}, B={a,b,c,d}
7
Mathematical definitions Sets A, B: A={1,2,3}, B={a,b,c,d} Cross-product A B: The set of all (a,b) pairs A B = {(1,a), (1,b), (1,c), (1,d), (2,a), (2,b), (2,c), (2,d), (3,a), (3,b), (3,c), (3,d)} 1 2 3 a b c d AB
8
Mathematical definitions Sets A, B: A={1,2,3}, B={a,b,c,d} Cross-product A B: The set of all (a,b) pairs A B = {(1,a), (1,b), (1,c), (1,d), (2,a), (2,b), (2,c), (2,d), (3,a), (3,b), (3,c), (3,d)} Relationship R: A subset of A B R = {(1,a), (2,c), (2,d), (3,b)} 1 2 3 a b c d AB
9
Makes Product name category price Company name Product and Company are sets of entities. Entities uniquely identified by primary keys. Makes is a relationship – a subset of Product Company. Tuples uniquely identified by pairs of Product & Company’s keys.
10
Product namepricecategory Gizmo19.99Electronics Powergizmo39.99Electronics Gadget19.99Toys name GizmoWorks GadgetCorp Company Product p × Company c p.namep.pricec.categoryc.name Gizmo19.99ElectronicsGizmoWorks Powergizmo39.99ElectronicsGizmoWorks Gadget19.99ToysGizmoWorks Gizmo19.99ElectronicsGadgetCorp Powergizmo39.99ElectronicsGadgetCorp Gadget19.99ToysGadgetCorp Makes Product name category price Company name
11
Product namepricecategory Gizmo19.99Electronics Powergizmo39.99Electronics Gadget19.99Toys name GizmoWorks GadgetCorp Company Product p × Company c p.namep.pricec.categoryc.name Gizmo19.99ElectronicsGizmoWorks Powergizmo39.99ElectronicsGizmoWorks Gadget19.99ToysGizmoWorks Gizmo19.99ElectronicsGadgetCorp Powergizmo39.99ElectronicsGadgetCorp Gadget19.99ToysGadgetCorp Makes Product name category price Company name Makes p.namep.pricec.categoryc.name Gizmo19.99ElectronicsGizmoWorks Powergizmo39.99ElectronicsGizmoWorks Gadget19.99ToysGadgetCorp
12
Can have multiple relationships between same entity sets. Each is a subset of Person Company with primary key (ssn, name). WorksFor PersonCompany OwnsStock Likes addressname ssn stockprice name
13
Can have relationship between single entity set. A subset of Person Person with primary key (ssn, ssn). Friend Person addressname ssn
14
Relationships can have attributes Product name category price Company name Makes since Relationship attributes are implicitly unique per (p.name, c.name).
15
Relationship vs. entity Product name category price Person p_id Purchased date Relationship attributes are implicitly unique per (name, p_id). What if we don’t want uniqueness?
16
Relationship vs. entity Product name category price Person p_id date Purchase quantitypurch_id ProductOfBuyerOf Representing as an entity allows multiple Purchases for each Product-Person combination.
17
Activity – Draw ER diagram Authors have IDs and names. They write books. Books have ISBNs and titles. The library keeps track of how many copies it has of the book. Each book is written by authors and published by a publisher. We want to know every time it is checked out by a borrower. Borrowers have a library card number, name, and address. They can check out a book on a particular date. Publishers have an ID, name and address. They publish books.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.