From data needs to ER Model to relational DB Schema Db Design Process From data needs to ER Model to relational DB Schema
NBA.com: the needs
What are the Entity sets? Name ID Type ? Location ? Location All “things” that listed in the banners? Entity (set) vs. Attribute: Should Location be an entity or an attribute? Team
2 relationships btw 2 entity sets: Is it possible? In every game, there are two teams engaged: One as the home team Another as away team Which one gives the correct answer? Game Game hasHm hasAw home away OR HomeTeam AwayTeam Team
Recursive relationship: what is it? Isn’t it true that each team just has one coach? What about specialty coaches and all the training staff? How to keep track them all and model the reporting structure? Team has reportsTo chief Coach asst
Relationship set or Entity Set: do it matter? Can I model the Game as a recursive relationship btw 2 (team) instances in the same Team entity sets? Would the outcome be any different? Game home PlaysAs away PlaysAs OR EngagedIn Team Game home Team away
The big picture: is it complete?
Cardinality constraints: why is it important? Three options 1:1 1:M/M:1 M:M (or M:N) # of tables needed 1 (or two, with other considerations) 2: with FK added to the many side 3: with a junction table for m:m mapping info which is as important as value in the attributes!
Convert into relational model Tables and columns: Each entity set becomes a table A many-to-many relationship set becomes a table Each (atomic) attribute becomes a column Keys: “Composite” key in the junction tables: PK from both related entity sets Surrogate key: independent from changes in business domain
Foreign keys FK specifies a constraint btw a referencing table and a referenced table It’s not a key in the referencing table (although may be part of the key) It’s a key in the referenced table (often the PK, but can be any candidate keys) It has as many attr’s (or columns) as its referenced key It’s added to the table on the many-side during the conversion Referential integrity can be enforced by requiring FK to take values existing in its referenced key
More Complex situations: N-ary What is N-ary (relationship)? All relationships that we discussed so far are binary? Can a R involve more E’s? Think about the PlayerStats entity set: it actually relates Player, Game in which a Player plays, and An entity in the StatsCategory entity set Common practice is to convert a N-ary R into N binary ones
More Complex situations: attributes Composite attributes Name Address Multi-valued attributes Player position: multiple positions at the same time, or during different periods Player stats or performance history
More Complex situations: weak entity Section of Course Section cannot exist without a Course Section has only got a partial key: (Section_No, Year, Semester) It needs to borrow PK from Course: (Course_No) to form a unique of its own: (Course_No , Section_No, Year, Semester) Course has Section