CS 564 Database Management Systems: Design and Implementation Arun Kumar Lecture 1: Entity-Relationship Modeling Chapter 2 in Cow Book Slide ACKs: AnHai Doan, Jeff Naughton, and Jignesh Patel
Database Design Process: ~6 steps Requirements Analysis Conceptual Database Design Logical Database Design Schema Refinement Physical Database Design Application and Security Design
Database Design Process: ~6 steps Requirements Analysis Conceptual Database Design Logical Database Design Schema Refinement Physical Database Design Application and Security Design Entity Relationship Modeling Relational Model and Normalization Indexing, etc.
ER Model Basics: Entity Entity: Distinguishable abstract real-world object An entity has several “Attributes” An attribute has a “Domain” A collection of similar entities is an “Entity Set” An entity set might have a “Key” attribute SID Name Age Student
ER Model Basics: Relationship Relationship: Association among ≥ 2 entities “Relationship Set” defined similarly SID Name Age DID Name Address Student Department Major EnrollDate
ER Model Basics: Relationship Set Mathematically, given entity sets A and B, a relationship set on A and B is a subset of A X B Student s2 s3 d2 d3 Department d1 s1 s4 Enroll relation: {(s1, d1), (s2, d1), (s3, d2), (s4, d3)}
Relationships in ER Multiple Relationships Multiplicity of Relationships Multi-way Relationships Self Relationships Multi-way to Binary Conversion
Multiple Relationships SID Name Age DID Name Address Major Student Department Advise Employ PID Name Age Professor
Multiplicity of Relationships b2 b3 b1 a1 a4 Student Department Many-to-one a2 a3 b2 b3 b1 a1 a4 Professor Department Many-to-many a2 a3 b2 b3 b1 a1 a4 Student Citizen One-to-one
Many-to-One and One-to-One in ER SID Name Age DID Name Address Major Student Department Arrow: Each Student appears at most once in Enroll, i.e., given a Student, the Department is unique (no double majors!) Student Name Age SID Citizen Address DID Match Q: How is Many-to-Many depicted?
The Cow Book denotes the above as follows: CAUTION: Difference with the Book SID Name Age DID Name Address Major Student Department The Cow Book denotes the above as follows: Student Name Age SID Department Address DID Major
Multi-way (n-ary) Relationships PID Name Age CID Name Credits Professor Course Teach Room DID Number Seats
Multi-way (n-ary) Relationships PID Name Age CID Name Credits Professor Course Teach Q: What does this mean? Room DID Number Seats
If “roles” are different, Self Relationships PID Name Age CID Name Credits Professor Course Teach PI Co-PI Collaborate Room DID Number Seats If “roles” are different, label the edges
Multi-way to Binary Conversion Professor Course Teach Professor Course Room InRoom ByProf OfCourse Teach Room Q: Why do we need these arrows?
Apart from types of Relationships, ER model can also capture Constraints
Constraints in ER Key: Uniquely identifies an entity Participation: Total or Partial Referential Integrity: Relationship “validity” Single-value Constraint Domain Constraints
Constraints: Key Student Room SID Name Age DID Number Seats Q: What does this mean?
Constraints: Participation Professor Name Age PID Department Address DID Employ Thick: Each Professor must appear at least once in Employ Student Name Age SID Department Address DID Major Q: So, what does this mean?
Constraints: Referential Integrity Professor Name Age PID Department Address DID Employ Curve: Each Professor must have a valid Department in Employ Student Name Age SID Department Address DID Major Q: So, what does this mean?
Advanced ER Concepts Weak Entities: an entity dependent on another Hierarchies: “Is a” relationships among entities
Advanced: Weak Entity PartOf Floor Department Number NumRooms DID Name Address PartOf Floor Department Thick/double lined shapes: Weak Entity and “dependency” DID and Number together are the Key for Floor Q. Why arrow, curve, and think line from Floor to PartOf? Q: Is a floor number ever meaningful without the Department?
Advanced: “Is A” Hierarchy Analogy: Sub-class Inheritance in PL SID Name Age Student IsA IsHonors QualScore Masters Undergrad Doctoral ByThesis
General ER Design Philosophy Follow Conventions Convey All App Constraints Avoid Redundancy Prefer Attributes over Trivial Entities
1. Follow Conventions Major Student Department Major Student
2. Convey All Application Constraints PID Name Age DID Name Address Employ Professor Department Q. What all constraints are missing here?
3. Avoid Redundancy Major Student Department SID Name Age DID Name Address Major Student Department DeptNAme
4. Prefer Attributes over Trivial Entities SID Name Age Name Major Student Department Q. What is wrong with the above? Student Name Age SID MajorDeptName
Review: ER Model Entity, Relationships Constraints Weak Entities; “IsA” Hierarchies Design Philosophy