Presentation is loading. Please wait.

Presentation is loading. Please wait.

IE 423 – Design of Decision Support Systems Database development – Relationships and Queries.

Similar presentations


Presentation on theme: "IE 423 – Design of Decision Support Systems Database development – Relationships and Queries."— Presentation transcript:

1 IE 423 – Design of Decision Support Systems Database development – Relationships and Queries

2 Table Design and Relationships NameRoo m PhoneArtistSong Bob212555- 1212 Jimmy Buffet Brown Eyed GirlSon of a Son of a Sailor Margaritaville Sam213555- 1232 SantanaDevil Woman Fred215555- 4455 BeatlesDear PrudenceAbbey RoadHey Jude …………… Mary234555- 1245 Sarah McLachlan SurfacingWinter SongAngel …………… Recall our music tracking system

3 Table Design and Relationships NameRoomPhoneArtistSong Bob212555-1212Jimmy BuffetMargaritavill e Bob212555-1212Jimmy BuffetBrown Eyed Girl Bob212555-1212Jimmy BuffetSon of a Son of Sailor …………… Mary234555-1245Sarah McLachlan Angel …………… Recall our music tracking system

4 Table Design and Relationships A relational database gets its power from the ability to manage multiple tables of data and the relationships among those tables MS Access is a relational database management system In designing and building a relational database you will define the tables (the fields and their properties, and The relationships among these tables

5 Splitting the previous table into two tables… IDNameRoomPhone 1Bob212555- 1212 2Mary234555- 1245 ………… IDArtistSong 1Jimmy Buffet Margarita ville 1Jimmy Buffet Brown Eyed Girl 1Jimmy Buffet Son of a Son of Sailor ……… 2Sarah McLachlan Angle 2Rolling Stones …

6 Database Design Splitting the previous table into two tables… More efficient We don’t have to reenter the people information for every song If we find a song in the song table how do we find the owner in the people table  In a relation one table has a field that is unique (no other record can have the same value This field is called a Primary Key  A related table will have a field with matching value (as the primary field in the other table), … but it does not have to be unique – This is called a foreign key  In our example, ID is the foreign key in the people table

7 Splitting the previous table into two tables… IDNameRoomPhone 1Bob212555- 1212 2Mary234555- 1245 ………… IDArtistSong 1Jimmy Buffet Margarita ville 1Jimmy Buffet Brown Eyed Girl 1Jimmy Buffet Son of a Son of Sailor ……… 2Sarah McLachlan Angle 2Rolling Stones …

8 So finding the owner of a particular song… We find a song in the music table, and get the ID value Go to the People table and find a record where the ID matches the one that we picking in the music table  music.id = people.id Once you have setup the database Access does all of this for you

9 Types of relationships in a relational database One to many – one record in table A matches (potentially) many records in table B One to one – one record in table A matches only one record in table B Many to many – records in table A can have multiple matching records in table B --- and vis- versa  This one is tricky  Consider an Orders table and a Products table

10 Referential Integrity (what?!) If a record in one table is linked (has a relationship) to one or more records in another table.. We must protect that link Referential Integrity – the assurance that this link does not get broken How could we violate referential integrity?  Delete a record on one side of the relation without first deleting linked records on the other side. If Bob moves we can’t delete his record from the people table without first deleting his songs from the music table  Add a record on the many side of the relation without the corresponding record existing on the one side of the relation We can’t add the new guy – Fernando’s songs to the music table unless Fernando’s information is in the people table

11 Database Development Let’s go back to our House Survey Data

12 Database Development Let’s go back to our House Survey Data

13 Neighbor08a.mdb

14

15

16 Remember that we split our House Survey data into two relations (tables) …so now we need to create a table for the rest of the data Don’t forget that each record must have a unique house identifier …and what we will use this for?

17 New tables for Neighbor08 database

18

19 Neighbor08a.mdb Make a relationship between these two tables How do you do this? What kind of relationship is this?

20 Neighbor08a.mdb Then, we are also interested in who lives in these houses… …so create another table for people You will need – PersonID HouseID –to tell which house they live in FirstName LastName DOB (what data type?) CellPhone (use an input mask)

21 Neighbor08a.mdb

22 Make a relationship between what two tables? How do you do this? What kind of relationship is this?

23 College.mdb Let’s look at another database Suppose you need to create a course registration system for college courses (or workshops, etc.) What are the objects that you need to work with? Students, Courses, ??? So, you have a table of students You have table of courses How do you relate these two tables? Does this present any problems?

24 College.mdb

25


Download ppt "IE 423 – Design of Decision Support Systems Database development – Relationships and Queries."

Similar presentations


Ads by Google