Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1
*** The “Online” Edition ***
Introduction to Data Management
Lecture #6 – Part 1(Relational DB Design)
Instructor: Mike Carey [email protected]
SQL
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 2
Today’s Notices
❖ Continue watching the wiki:▪ http://www.ics.uci.edu/~cs122a/
❖ And also Piazza, of course:▪ http://piazza.com/uci/spring2020/cs122a/home
❖ Online textbook version available ($35)▪ https://create.mheducation.com/shop/#/catalog/details/?isbn=9781307574180
❖ HW#1 is due! (24-hour/10-point grace period)▪ ShopALot.com (parking lot shopping for stores)
❖ HW #2 will be available later on tonight!▪ Start thinking now; HW #1’s solution out tomorrow
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 3
Wait! Clarifying IsA Mappings...
Contract_Emps
namessn
Employees
lot
hourly_wagesIsA
Hourly_Emps
contractid
hours_worked
covering
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 4
Delta Table Approach
ssn name lot
1 Joe 12
2 Shelly 16
3 Arvind null
4 Chen 11
ssn wages hrs_worked2 15 40
4 250 10
ssn contract_id3 101
4 102
Employees
Hourly_Emps Contract_Emps
Note 1: Joe can’t really exist here (covering)
Note 2: Chen couldn’t exist if we’d said disjoint
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 5
Union Table Approach
ssn name lot
1 Joe 12
ssn name lot wages hrs_worked2 Shelly 16 15 40
4 Chen 11 250 10
ssn name lot contract_id3 Arvind null 101
4 Chen 11 102
Employees
Hourly_Emps Contract_Emps
Note 3: No CREATE TABLE way to prevent ssn duplication
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 6
Mashup Table Approach
ssn is_hourly is_contract name lot wages hrs_worked contract_id1 false false Joe 12 null null null
2 true false Shelly 16 15 40 null
3 false true Arvind null null null 101
4 true true Chen 11 250 10 102
Employees
Note 4: Might want to create VIEWs on top...
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 7
Relational Model and E-R Schema Translation: Summary❖ Relational model: Tabular representation of data.❖ Simple and intuitive, and very widely used.❖ Integrity constraints specified by DBA based on
application semantics. DBMS checks for violations. ▪ Two important ICs: Primary and foreign keys (PKs, FKs).▪ In addition, we always have domain (type) constraints.
❖ Powerful and natural query languages exist (soon!)❖ Rules to translate E-R to relational model
▪ Can be done by a human, or automatically (using a tool)▪ Entities, relationships, attributes, cardinality, participation,...▪ IsA handling; composite, multi-valued, and derived attributes
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 8
Relational Database Design❖ Two aspects to the RDB design problem:
▪ Logical schema design: We just saw one approach, namely, doing E-R modeling followed by an E-R to relational schema translation step
▪ Physical schema design: Later, once we learn about indexes, how and when should we utilize them?
❖ We will look at both problem aspects this term, starting with relational schema design▪ Our power tools will be functional dependencies
(FDs) and normalization theory▪ Note: FDs also play an important role in other
contexts as well, e.g., SQL query optimization
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 9
So, Given a Relational Schema...
❖ How do I know if my relational schema is a “good” logical database design or not?▪ What might make it “not good”?▪ How can I fix it, if indeed it’s “not good”?▪ How “good” is it, after I’ve fixed it?
❖ Note that your relational schema might have come from one of several places▪ You started from an E-R model (but maybe that
model was “wrong” or incomplete in some way?)▪ You went straight to relational in the first place▪ It’s not your schema – you inherited it! ☺
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 10
Ex: Wisconsin Sailing Club
sid sname rating age date bid bname color
22 Dustin 7 45.0 10/10/98 101 Interlake blue22 Dustin 7 45.0 10/10/98 102 Interlake red22 Dustin 7 45.0 10/8/98 103 Clipper green22 Dustin 7 45.0 10/7/98 104 Marine red31 Lubber 8 55.5 11/10/98 102 Interlake red31 Lubber 8 55.5 11/6/98 103 Clipper green31 Lubber 8 55.5 11/12/98 104 Marine red... ... ... ... ... ... ... ...
Proposed schema design #1:
Q: Do you think this is a “good” design? (Why or why not?)Q: And – new Sailor, or new Boat...?
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 11
Ex: Wisconsin Sailing Club
sid sname rating age
22 Dustin 7 45.031 Lubber 8 55.5... ... ... ...
sid bid date
22 101 10/10/9822 102 10/10/9822 103 10/8/9822 104 10/7/9831 102 11/10/9831 103 11/6/9831 104 11/12/98... ... ...
bid bname color
101 Interlake blue102 Interlake red103 Clipper green104 Marine red
Proposed schema design #2:
Q: What about this design?• Is design #2 “better than
#1...? Explain!• Is it a “best” design?• How can we go from
design #1 to this one?
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 12
Ex: Wisconsin Sailing Club
sid sname rating age
22 Dustin 7 45.031 Lubber 8 55.5... ... ... ...
sid bid date
22 101 10/10/9822 102 10/10/9822 103 10/8/9822 104 10/7/9831 102 11/10/9831 103 11/6/9831 104 11/12/98... ... ...
bid bname
101 Interlake102 Interlake103 Clipper104 Marine
Proposed schema design #3:
Q: What about this design?• Is #3 “better” or “worse”
than #2...?
bid color
101 blue102 red103 green104 red