Presentation is loading. Please wait.

Presentation is loading. Please wait.

U:/msu/course/cse/103 Day 03, Slide 1 CSE 103 Day 15: Database Design Students: –Read Day 2 in your textbook –Your BT feedback.

Similar presentations


Presentation on theme: "U:/msu/course/cse/103 Day 03, Slide 1 CSE 103 Day 15: Database Design Students: –Read Day 2 in your textbook –Your BT feedback."— Presentation transcript:

1 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 1 CSE 103 Day 15: Database Design Students: –Read Day 2 in your textbook –Your BT feedback may be (hopefully is!) up Others: –Please save your work and log out by 10:10.

2 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 2 Day 13/14 Review Day 13: Nested queries in MySQL –Write subqueries to find data needed before we can answer the problem –Compare subqueries with exactly one record & field using = > < etc. –In FROM clause, subqueries make virtual tables we name with AS Day 14: BT day. Comments/feedback on your BT? –"It was too hard" doesn't count

3 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 3 Database terminology review Record –An item in your database, usually represented by one row in your database –Also called entity, object –Tables contain records about objects of the same type Field –A piece of information about an object –Also called attribute –Stored in columns in your database

4 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 4 Database Design What questions do I want the database to answer? What data do I need to answer these questions? How are these data related to one another?

5 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 5 Guiding Principles Control data Redundancy –Don't (redundantly) store data in two places (twice) Maintain data Consistency –Don't store conflicting data Provide data Integrity –Only allow legal values; all records must have primary keys Maintain data Independence –Changing data in one place does not break DB in other places

6 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 6 Database Example: Electronic Rolodex What information about your friends would you like a rolodex to provide? What data is in the SBC phonebook white pages? What data isn't available in the SBC phone book that you would like to have in your personal phonebook? How would you arrange this data in a database table? How would you arrange this data in a database table?

7 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 7 Database Example: Electronic Rolodex, cont’d What questions do you want to be able to answer about your friends? What items of data do we need in our contact directory in order to answer such questions? What should you do when you can't get some of the data? For example, you don't know all of your friends' addresses. What should you do with people who have more than one phone number: a cell phone number, a pager number, a fax number?

8 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 8 Data types Examine the list of data types on page 2-5 of the text Within your group, reach a consensus on the datatype assigned to each piece of data in your design Note: this data will be made available in the day 15 AFS space after we have agreed on types as a class

9 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 9 Design View for a Table Start Access and create a new database called contacts.mdb Create a new table in design view, and enter the field names and data types (as agreed) Use descriptive field names close to those discussed in class so that you don't need any additional information in the Description box –NEVER USE SPACES IN FIELD NAMES! –Try to follow a consistent convention, e.g., all lower- case, first capital, underscores between words, etc. Pick your own but BE CONSISTENT! Don't save the table yet

10 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 10 Saving the Table Use naming convention: –To tell difference between table and query, we use tbl_ and qry_ –Not required—some people don't use any convention, but recommended to use it Following the naming convention, call the table tbl_People. Access will prompt you about a primary key. Answer no for now and continue to next slide.

11 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 11 Primary Keys What does the primary key do? What is a reasonable primary key for this table? (see next slide)

12 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 12 Types of Primary Keys Existing data: –e.g., Social Security #, PID, filename, etc. –One item that uniquely identifies an object Multiple cell: –e.g., ActorID + MovieID = Role (list of Actors in Movies); TextbookID + AuthorID = BookAuthor (books’ authors) –The combination of all fields uniquely identifies an object: same actor can’t be in same movie, but one actor can be in multiple movies, and one movie may have multiple actors Autonumber: –Last resort, used when nothing else works –The DBMS assigns a new unique # when you insert a row –Wastes space if you could find a key among existing data –Doesn't help prevent duplicate entries (can always insert; get new key every time even if all other data is the same)

13 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 13 Closing & data entry Set the primary key, save, and close the table Open it in datasheet view and add information about yourself Remember that we don't ever save the database itself –All data changes are live –Changes to table or query designs have to be saved

14 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 14 Better design, first steps: Properties of data What pieces of information does every person have: –Exactly one of –Exactly zero or one of –Any number between zero and at least two What pieces of information might be shared between multiple people?

15 http://www.cse.msu.edu/~cse103 U:/msu/course/cse/103 Day 03, Slide 15 Homework Check the homework link. –Enter 15 records into your contact directory. (Suggest you use classmates right after class!) –Practice identifying primary keys –Read Day 10 on the design of multiple-table databases –Think about how we could improve the design of the contacts database (see questions on previous slide)


Download ppt "U:/msu/course/cse/103 Day 03, Slide 1 CSE 103 Day 15: Database Design Students: –Read Day 2 in your textbook –Your BT feedback."

Similar presentations


Ads by Google