Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE...

12
http://www.cse.msu.edu/ http://www.cse.msu.edu/ ~cse103 ~cse103 U:/msu/course/cse/103 U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 1 CSE 103 Day 18 CSE 103 Day 18 If you are not enrolled in CSE If you are not enrolled in CSE 103, please save and log out by 103, please save and log out by 10:10. 10:10. Students: Students: Finish MegaCorp import (if logged Finish MegaCorp import (if logged in)! in)! Today: Last day of Access! Today: Last day of Access! Review Day 12 in the textbook Review Day 12 in the textbook

Transcript of Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE...

Page 1: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 11

CSE 103 Day 18CSE 103 Day 18

If you are not enrolled in CSE 103, please If you are not enrolled in CSE 103, please save and log out by 10:10.save and log out by 10:10.

Students:Students:– Finish MegaCorp import (if logged in)!Finish MegaCorp import (if logged in)!– Today: Last day of Access! Today: Last day of Access! – Review Day 12 in the textbookReview Day 12 in the textbook

Page 2: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 22

Review of Day 17 Homework Review of Day 17 Homework QueriesQueries

Create a list of suite descriptions with the Create a list of suite descriptions with the accompanying product descriptions, accompanying product descriptions, quantities and number in stock. quantities and number in stock. (qry_hw11_suiteMakeup) (qry_hw11_suiteMakeup) [42][42]

Modify this query to also list the color Modify this query to also list the color name of each product and to order the list name of each product and to order the list by suite. by suite. (qry_hw11_suite&color) (qry_hw11_suite&color) [still 42!][still 42!]

Page 3: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 33

Redundancy and ConsistencyRedundancy and Consistency

See pages 1-17 and 1-18, as well as See pages 1-17 and 1-18, as well as pages 12-2 and 12-3.pages 12-2 and 12-3.

– What is Data Redundancy?What is Data Redundancy?How can it be controlled?How can it be controlled?

– What is Data Consistency?What is Data Consistency?How can it be assured?How can it be assured?

– What is Entity Integrity?What is Entity Integrity?How can it be enforced in Access?How can it be enforced in Access?

– What is Referential Integrity?What is Referential Integrity?

Page 4: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 44

Referential Integrity in AccessReferential Integrity in Access

In In MegaCorpMegaCorp, choose Tools -> Relationships , choose Tools -> Relationships Right-click, Show Table: Right-click, Show Table: ProductsProducts and and ColorsColorsCreate a relationship like you would a join: by Create a relationship like you would a join: by dragging a line to connect fieldsdragging a line to connect fields– One should be the primary key of a table!One should be the primary key of a table!

Access asks if you want to enforce integrity, and Access asks if you want to enforce integrity, and if you want to use Cascade Update/Deleteif you want to use Cascade Update/Delete– Cascade UpdateCascade Update: When a primary key changes, copy : When a primary key changes, copy

the new value to the related foreign keythe new value to the related foreign key– Cascade DeleteCascade Delete: When a record with a primary key : When a record with a primary key

value is deleted, also delete all records having that value is deleted, also delete all records having that value in a value in a related related foreign key fieldforeign key field

Page 5: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 55

MegaCorpMegaCorp Relationships Relationships

Use the relationship window to create Use the relationship window to create relationships between tables in the relationships between tables in the MegaCorpMegaCorp database database– When would you want Cascade Update or When would you want Cascade Update or

Cascade Delete?Cascade Delete?– When would you not?When would you not?

Field names do not have to match to make Field names do not have to match to make a relationship, but datatypes must matcha relationship, but datatypes must match– Autonumber matches with Number (not Auto)Autonumber matches with Number (not Auto)

Page 6: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 66

Problems in Problems in music-day08music-day08 db db

These questions are "what if" only. Some These questions are "what if" only. Some of these could of these could damagedamage your database, so your database, so do not actually change your data!do not actually change your data!What would happen if you were to change What would happen if you were to change MP3 to MP4 in the MP3 to MP4 in the DigitalFormatDigitalFormat field of field of the the DigitalTracksDigitalTracks table?  Why? table?  Why?What would happen if you were to delete What would happen if you were to delete the Elektra/Asylum row from the the Elektra/Asylum row from the LabelsLabels table?  Why?table?  Why?

Page 7: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 77

Relationships in Relationships in music-day08music-day08

Create relationships and try to enforce Create relationships and try to enforce referential integrity in your referential integrity in your music-day08music-day08 databasedatabase– Don't create one for Don't create one for Secondary ArtistSecondary Artist

What problems do you run into?What problems do you run into?– Read any error messages carefully, then Read any error messages carefully, then

investigate the table or tables that have the investigate the table or tables that have the problem. How could we solve this?problem. How could we solve this?

Page 8: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 88

Lookup FieldsLookup FieldsHave we solved the problem illustrated by:Have we solved the problem illustrated by:– What would happen if you were to change MP3 to What would happen if you were to change MP3 to

MP4 in the MP4 in the DigitalFormatDigitalFormat field of the field of the DigitalTracksDigitalTracks table?table?

Lookup Fields can restrict field values (See Lookup Fields can restrict field values (See Access 2000 HELP on how to define and use)Access 2000 HELP on how to define and use)– Makes data entry in Datasheet view much easierMakes data entry in Datasheet view much easier

Fix the problem in the Fix the problem in the LabelsLabels and and AlbumsAlbums tables, tables, then change the then change the LabelLabel field in field in tbl_Albumstbl_Albums into a into a Lookup FieldLookup Field

Carl Bussema III
You'll want to debrief the last exercise and make a note of how to fix Labels/Albums before going on.
Page 9: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 99

contactscontacts DB Relationships DB Relationships

Define relationships in your Define relationships in your contactscontacts db dbEnforce referential integrity in these Enforce referential integrity in these relationshipsrelationshipsAdd a table Add a table tbl_PhoneTypestbl_PhoneTypes to restrict the to restrict the possible types of phonespossible types of phonesAllow only these types in the related field Allow only these types in the related field in in tbl_PhoneNumberstbl_PhoneNumbers– Could you write a quick query to find all the Could you write a quick query to find all the

different PhoneTypes from that field?different PhoneTypes from that field?

Page 10: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 1010

HomeworkHomework

Click on the Homework link on today’s Click on the Homework link on today’s classwork page to find out what must be classwork page to find out what must be done before taking the 2.5 BTdone before taking the 2.5 BTHighlights:Highlights:– Add and use Add and use tbl_AddressTypestbl_AddressTypes in in contacts contacts dbdb– Add more lookup fields in Add more lookup fields in MegaCorp MegaCorp dbdb– Queries on tables with lookup fieldsQueries on tables with lookup fields– After the BT we will begin working on dynamic After the BT we will begin working on dynamic

Web pages. Review basic HTML from CSE Web pages. Review basic HTML from CSE 101, Days 6-7 (use the101 Web site).101, Days 6-7 (use the101 Web site).

Page 11: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 1111

Bridge Task 2.5Bridge Task 2.5Covers all materials from Day 15 through and Covers all materials from Day 15 through and includingincluding Day 18 Day 18– Design, design, and more designDesign, design, and more design

Datatypes and primary keysDatatypes and primary keysAdding a new table or tables to an existing databaseAdding a new table or tables to an existing databaseDesigning a multiple-table databaseDesigning a multiple-table databaseRelationships and referential integrityRelationships and referential integrityLookup fieldsLookup fields

Review text, Web and homeworkReview text, Web and homeworkBring books, notes, back-up disk, photo ID, etc. Bring books, notes, back-up disk, photo ID, etc. Practice BT is availablePractice BT is available– Answer to design problem will be in course AFS spaceAnswer to design problem will be in course AFS space

Page 12: Http://cse103 U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.

http://www.cse.msu.edu/~cse103http://www.cse.msu.edu/~cse103U:/msu/course/cse/103U:/msu/course/cse/103 Day 18, Slide Day 18, Slide 1212

Homework you must have done Homework you must have done before the BT 2.5before the BT 2.5

Contacts:Contacts:– 15 records in tbl_People15 records in tbl_People– Phones and Addresses N:M relationships (2 tables Phones and Addresses N:M relationships (2 tables

each + “Types” table makes 3)each + “Types” table makes 3)– Email 1:N relationship (1 table)Email 1:N relationship (1 table)– Referential Integrity enforced on all relationshipsReferential Integrity enforced on all relationships

MegaCorp:MegaCorp:– All data importedAll data imported– Referential Integrity enforcedReferential Integrity enforced– Lookup fieldsLookup fields