Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this...

11
http://www.cse.msu.edu/ http://www.cse.msu.edu/ ~cse103 ~cse103 U:/msu/course/cse/103 U:/msu/course/cse/103 Day 17, Slide Day 17, Slide 1 CSE 103 CSE 103 Housekeeping: Housekeeping: Take a makeup BT this week if not passed Take a makeup BT this week if not passed the 2.0 yet the 2.0 yet Next in-class one week from today Next in-class one week from today Today: Advanced Design. Review Days 2 Today: Advanced Design. Review Days 2 and 10 in the book. and 10 in the book. Remember: Office Hours MW 3-5, TR 2-4* Remember: Office Hours MW 3-5, TR 2-4* in 1107 EB; Help Room MT 9-11pm in 120 in 1107 EB; Help Room MT 9-11pm in 120 CC CC * or by appointment (email * or by appointment (email [email protected]) [email protected])

Transcript of Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this...

Page 1: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

CSE 103CSE 103

Housekeeping:Housekeeping:– Take a makeup BT this week if not passed the Take a makeup BT this week if not passed the

2.0 yet2.0 yet– Next in-class one week from todayNext in-class one week from today– Today: Advanced Design. Review Days 2 and Today: Advanced Design. Review Days 2 and

10 in the book.10 in the book.– Remember: Office Hours MW 3-5, TR 2-4* in Remember: Office Hours MW 3-5, TR 2-4* in

1107 EB; Help Room MT 9-11pm in 120 CC1107 EB; Help Room MT 9-11pm in 120 CC* or by appointment (email [email protected])* or by appointment (email [email protected])

Page 2: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

Multiple Table Database ReviewMultiple Table Database Review

What are What are entitiesentities? ?

What are What are recordsrecords ? ?

What are What are attributesattributes??

How can you represent a How can you represent a 1:N1:N (one-to- (one-to-many) many) relationshiprelationship??

How can you represent an How can you represent an M:NM:N (many-to- (many-to-many) many) relationshiprelationship??

Page 3: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

MegaCorp DatabaseMegaCorp DatabaseDesign a new database for inventory usageDesign a new database for inventory usageMegaCorp manufactures office MegaCorp manufactures office furniturefurniture::– Bookcases, File Cabinets, Desks, ChairsBookcases, File Cabinets, Desks, Chairs

Desks and Chairs come in three Desks and Chairs come in three stylesstyles::– Contemporary, Traditional, ClassicContemporary, Traditional, Classic

All furniture items have:All furniture items have:– ColorColor: beige, oak, walnut, mahogany, black: beige, oak, walnut, mahogany, black– SizeSize: depth, width, height (in inches, to hundredths): depth, width, height (in inches, to hundredths)– DescriptionDescription, , Item NumberItem Number

It is necessary also to keep a record of the It is necessary also to keep a record of the number number of each item in stockof each item in stock

Page 4: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

Database DesignDatabase DesignLevel 1Level 1

What What questionsquestions do I want the database to do I want the database to answer?answer?

What What datadata do I need to answer these do I need to answer these questions?questions?

How are these data How are these data relatedrelated to one to one another?another?

Page 5: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

Database DesignDatabase DesignLevel 2Level 2

What What entitiesentities are involved? are involved?What What attributesattributes belong to each entity? How many of belong to each entity? How many of each attribute does each entity have?each attribute does each entity have?– Exactly one?Exactly one?– Exactly zero or one?Exactly zero or one?– Anywhere from zero to two or more?Anywhere from zero to two or more?

Do any two or more entities have the same value for any Do any two or more entities have the same value for any attribute?attribute?What What datatypedatatype should be used for each of the different should be used for each of the different attributes?attributes?What What relationshipsrelationships exist between these entities? What exist between these entities? What typetype is each of these relationships? is each of these relationships?

Page 6: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

Database Design SequenceDatabase Design Sequence

Use a “Use a “Relational Database DiagramRelational Database Diagram” with ” with boxes and connecting lines to initially identify boxes and connecting lines to initially identify entities, attributes and relationships.entities, attributes and relationships.Next convert boxes to tables and attributes to Next convert boxes to tables and attributes to columns. Define primary keys.columns. Define primary keys.Implement each one-to-many relationship via the Implement each one-to-many relationship via the use of a foreign key in the “many” entity.use of a foreign key in the “many” entity.Implement each many-to-many relationship via Implement each many-to-many relationship via an extra “relationship table” which uses the an extra “relationship table” which uses the pairpair of foreign keys as its primary key.of foreign keys as its primary key.

Page 7: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

General Design GuidelinesGeneral Design GuidelinesDatabase designing should be an Database designing should be an iterativeiterative process. As difficulties appear at one process. As difficulties appear at one stage, you may need to go back and refine stage, you may need to go back and refine or modify earlier stages.or modify earlier stages.

Try to Try to reducereduce redundancies and redundancies and dependencies (dependencies (normalizationnormalization).).

FinishFinish the design before entering data! the design before entering data!

Page 8: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

Begin designBegin design

Work Work with your groupswith your groups. See . See slide 2slide 2 for specs. for specs.– Create a Relational Database Diagram (slide 5) and Create a Relational Database Diagram (slide 5) and

write out your tables on paperwrite out your tables on paper– Think about questions on slides 3-4 as you workThink about questions on slides 3-4 as you work– Elect group spokesperson to share design with rest of Elect group spokesperson to share design with rest of

class; we’ll compare notes and come to agreementclass; we’ll compare notes and come to agreement

10 minutes to work without our help10 minutes to work without our help15 more minutes after that15 more minutes after thatNo need to put anything in Access yet (but you No need to put anything in Access yet (but you can if you finish the rest, just be prepared to can if you finish the rest, just be prepared to change if needed)change if needed)

Page 9: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

MegaCorp PackagesMegaCorp PackagesMegaCorp wants to sell MegaCorp wants to sell suitessuites/groupings of /groupings of furniture items.furniture items.Each suite consists of a variety of items in Each suite consists of a variety of items in different quantities and has a suite name and a different quantities and has a suite name and a total price. An item may belong to any number of total price. An item may belong to any number of suites at the same time.suites at the same time.Modify your design to handle “suites”.Modify your design to handle “suites”.– Again use questions on slides 3-4 to guide youAgain use questions on slides 3-4 to guide you– Work on paper first, only go to Access if your group has Work on paper first, only go to Access if your group has

reached agreement (again, be prepared to change)reached agreement (again, be prepared to change)– 10 minutes without help, then 10 more10 minutes without help, then 10 more

Page 10: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

Create your MegaCorp DBCreate your MegaCorp DB

If you haven’t already, create a database called If you haven’t already, create a database called MegaCorp in your personal AFS spaceMegaCorp in your personal AFS space– If you already started one, you can rename it if you If you already started one, you can rename it if you

close Accessclose Access

Create tables as per discussion, with fields as Create tables as per discussion, with fields as shownshown– Use tbl_ prefix for table namesUse tbl_ prefix for table names– Select appropriate data types for every fieldSelect appropriate data types for every field– Set primary keys for every tableSet primary keys for every table– Field descriptions are optionalField descriptions are optional

Page 11: Http://cse103 U:/msu/course/cse/103 Day 17, Slide 1 CSE 103 Housekeeping: –Take a makeup BT this week if not passed the 2.0 yet –Next.

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

HomeworkHomework

Check the link on today’s classwork page Check the link on today’s classwork page for the homework for next class day.for the homework for next class day.Highlights (check web page for full details)Highlights (check web page for full details)– Finish/check Megacorp DB designFinish/check Megacorp DB design– Import data into MegacorpImport data into Megacorp– Queries in Megacorp to test your import and Queries in Megacorp to test your import and

understandingunderstanding– HAVE THE IMPORT DONE BEFORE NEXT HAVE THE IMPORT DONE BEFORE NEXT

CLASS! E-MAIL with questions/problems.CLASS! E-MAIL with questions/problems.