Presentation is loading. Please wait.

Presentation is loading. Please wait.

U:/msu/course/cse/103 Day 16, Slide 1 CSE 103 Day 16 Students: Read Day 10. If you are logged in, add records to your contacts.

Similar presentations


Presentation on theme: "U:/msu/course/cse/103 Day 16, Slide 1 CSE 103 Day 16 Students: Read Day 10. If you are logged in, add records to your contacts."— Presentation transcript:

1 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 1 CSE 103 Day 16 Students: Read Day 10. If you are logged in, add records to your contacts DB (need 15). Sign-up for a makeup before you leave for break! Others: Please save your work and log out by 10:10.

2 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 2 Day 15 Review What datatype would be an appropriate choice for: –A cell phone number –A favorite color –A birthday or anniversary What was the primary key for tbl_People? Why? What did we do about missing data?

3 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 3 Primary Key Exercise Review In the Primary Key Exercise from Day 15, what keys did you set for: –tbl_PlayerHistory –tbl_Games –tbl_Tasks What fields did you create for tbl_EmployeeTaskAssignments? –What was the primary key?

4 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 4 Day 16: Intermediate Design; Updating single-table designs What information in your contacts database is stored poorly? –Many of the records have NULL values –Some records contain the same value Can we group some of this information together somehow? If we move data to another table, how do we relate it back to ? If we move data to another table, how do we relate it back to tbl_People?

5 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 5 Contacts Database The database contacts.mdb currently consists of a single table We now need to accommodate a wide variety of e-mail data –Some friends have school, work, personal accounts –Some family members don't have any e-mail at all! How should we change the contacts database to best handle this new data? What type of relationship is needed? –Assume that no one shares an e-mail address

6 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 6 Four Steps to Redesign the contacts database Design the new tbl_Emails table –Fields, Names, Datatypes –We will make the assumption that an e-mail address can belong only to one person (without this assumption, we would need several extra steps) Transfer the existing data to the new table and CHECK YOUR RESULTS Delete the unneeded column(s) from the original table (But once they’re gone…) Enter any new e-mail information

7 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 7 First Step Design the new tbl_Emails table –Fields, Names, Datatypes –Remember: This table is to describe the “Emails” entity, not People Information not related to an e-mail address doesn't belong here! –What is an appropriate primary key? –What foreign key(s) might you need to use? When you make a new table, it should (almost always) have a foreign key from at least one other table

8 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 8 Next Steps Transfer the existing data to the new table using action queries –CHECK THE RESULTS!!! Delete the unneeded column(s) from the tbl_People table (AFTER checking the results of the previous step!) –Use design view, not a delete query (delete queries remove rows, not columns) Enter any new e-mail information in the new table tbl_Emails

9 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 9 Redesign debrief What is the primary key in the new tbl_Emails table? Is there a foreign key in the tbl_Emails table? If so, what one? How was the data transferred? What column(s) needed to be removed? What difficulties were encountered?

10 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 10 Updating database exercise Note the size of your contacts database file now and again after these steps. Update the datatype and length of each field in both tables to what is actually needed in order to accommodate the data Use the Tools menu to compact (called compact & repair in some versions of Access) your contacts database How was the size of your file affected?

11 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 11 More redesigning: Phones Obviously some people have many different phones –Home, Cell, Work, Work Cell, Work Fax, etc. Some phone numbers belong to more than one person –Roommates, families –Fax machines We need a compact way to represent this data without redundancy and without excessive NULL values in fields

12 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 12 Four steps to redesign contacts for phones Make new table(s) as needed –Identify your relationship(s). If you have any M:N relationships, you need an extra table. Transfer the existing data into the new table(s) and CHECK THE RESULTS Delete the redundant info from the original table(s) (AFTER checking) Enter any new data into the new table(s)

13 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 13 Phones redesign, steps 1 and 2 What type of relationship is this? What table or tables do we need? What type of data should go in each table? What is the primary key of each table? How can we copy data into the right places? How do we make sure it gets linked up correctly?

14 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 16, Slide 14 Homework Check the Homework link on today’s Classwork page for homework to do for Day 17 –Transfer addresses like we did phones –Finish redesigns from class (Phones, Emails)


Download ppt "U:/msu/course/cse/103 Day 16, Slide 1 CSE 103 Day 16 Students: Read Day 10. If you are logged in, add records to your contacts."

Similar presentations


Ads by Google