Download presentation
Presentation is loading. Please wait.
Published byAbigail Cook Modified over 9 years ago
1
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 1 Debrief Homework What problems arose in trying to import the data from Classical_Music.xls? –Duplicate entries (both Artists and Albums) –Need to enter foreign key into the table tbl_Albums rather than the actual label name –Need to enter foreign keys into the table tbl_PerformsIn rather than the actual artist name and album title So copy the file musicDay08.mdb to use
2
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 2 Debrief Relations What are the three types of relations? What are examples of each type in our databases? How do you implement each type?
3
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 3 Database Design Using tables and relations between the tables allows us to store information with a minimum of redundancy How do we extract information from a multi-table database? –How do multi-table queries incorporate the relations between the tables? –e.g., Which albums were released on the Sony label?
4
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 4 Questions about JOINS The JOIN operation is discussed on 8-2 and 8-3 of the textbook. What are the three steps in the JOIN operation called? What is meant by each of these terms?
5
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 5 Pencil and Paper JOIN Exercise Worksheet with two tables –tbl_Tracks and tbl_Albums The JOIN table is partially complete –First operation is unfinished Complete all steps of the JOIN operation Which rows are left in the final JOIN table? How many columns are there?
6
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 6 Constructing a Multi-Table Query in SQL on musicDay08 First operation: PRODUCT SELECT AlbumID, AlbumTitle, AlbumYear, LabelID, NumTracks, NumDiscs, TrackID, TrackNumber, Title, Album, [Secondary Artist], Duration FROM tbl_Albums, tbl_Tracks WHERE (AlbumID=15 OR AlbumID=28 OR AlbumID=33) AND (TrackID=85 OR TrackID=88 OR TrackID=279 OR TrackID=413 OR TrackID=415) AND (TrackID=85 OR TrackID=88 OR TrackID=279 OR TrackID=413 OR TrackID=415)
7
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 7 Query Construction, cont. What condition should we enforce to get only those records from the two tables that match on the common attribute? (SELECT) How many rows are returned now? How can we remove the duplicate column? (PROJECT) How can we construct this same query in Design View?
8
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 8 Compare Generated SQL What is different about the SQL in this query? –It uses (tbl_Albums INNER JOIN tbl_Tracks ON tbl_Albums.AlbumID = tbl_Tracks.Album) instead of restricting in the WHERE clause. Is there any difference in the results when you run the query? This syntax is newer and now preferred. –Easier for the RDBMS to optimize
9
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 9 Multiple Table Queries in SQL Construct the following queries in SQL View –list the albums (title and year) with the name of their label (qry_day08_albums_with_labels) [42] –list the digital tracks with their title, duration, and digital filesize (qry_day08_digital_tracksizes) [362] –list the tracks in the database (track number and title) with the name of their secondary artist (qry_day08_secondary_artists) [9]
10
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 10 Pencil and Paper Exercise on Relation Tables Does it matter which tables we join first? What does the shaded area in the upper right-hand corner of the worksheet represent? Which two tables should be joined next to complete the relational JOIN table? How many rows does the resulting JOIN have?
11
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 11 Verify your results using Access The AlbumIDs and ArtistIDs in the worksheet correspond with those in the music database in the Day 08 AFS space –Sufficient to restrict the tbl_PerformsIn to have ID’s from those listed in both columns –tbl_Artists and tbl_Albums need only restrict the ID Construct a query that performs the join of all three tables (qry_day08_three_table_join)
12
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 12 Bridge Task 1.5 INDIVIDUAL, not group work Everyone should come –You will get the next BT you have not yet passed, either 1.0 or 1.5 –If you take the 1.0 BT, you can schedule a makeup to take the 1.5 BT as soon as you pass the 1.0 Material on days 6, 7 and 8, –Importing, Relations, Joins, Multi-Table Queries Bring textbook, all notes, etc.
13
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 13 Bridge Task 1.5 Review textbook, Web pages, homework All class, homework materials on AFS space –Today's classwork files –Today’s homework
14
http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 08, Slide 14 Homework Check the link on the today page for homework to do in advance of the BT on Day 9. You need to construct some queries on your contacts database.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.