Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mark Dixon Page 1 03 – Database Design: Multiple Tables.

Similar presentations


Presentation on theme: "Mark Dixon Page 1 03 – Database Design: Multiple Tables."— Presentation transcript:

1 Mark Dixon Page 1 03 – Database Design: Multiple Tables

2 Mark Dixon Page 2 Session Aims & Objectives Aims –To add dealing with multiple tables to your understanding of databases Objectives, by end of this week’s sessions, you should be able to: –identify duplicated data in a single table –split that table to reduce data redundancy

3 Mark Dixon Page 3 Record Field Flat files: Data Duplication Track TitleArtist NameCountry ParanoidBlack SabbathUK Falling in LoveAerosmithUS PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track

4 Mark Dixon Page 4 Problem: Data Duplication takes up lots of space can become inconsistent (misspellings) difficult to search (misspellings) difficult to change (need to change each instance)

5 Mark Dixon Page 5 Relations (tables) Track TitleArtist ID Paranoid1 Falling in Love2 Pink2 Love in an Elevator2 Smooth Criminal3 Meaning of Life4 The Game4 Voices4 Down with the Sickness4 Artist ID Artist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS 4DisturbedUS Track Artist Primary Key Foreign Key

6 Mark Dixon Page 6 Normalisation Part of database design Process of breaking data down Codd –7 stages of normalisation Mathematical Difficult to apply stages Most professionals do it instinctively

7 Mark Dixon Page 7 Question: Prescriptions Identify duplication and separate: DateSurnameForenamesDrug Name 6 Jan 04JonesAlisonCo-codamol 11 Jan 04SmithBobTegretol 18 Jan 04HopeJohnCo-codamol 5 Feb 04JohnsonSallyCo-codamol 8 Feb 04SmithBobTegretol 10 Feb 04SmithBobSorbitol Prescription

8 Mark Dixon Page 8 Question: Solution DatePatientIDDrugID 6 Jan 0411 11 Jan 0422 18 Jan 0431 5 Feb 0441 8 Feb 0422 10 Feb 0423 Prescription PatientIDSurnameForenames 1JonesAlison 2SmithBob 3HopeJohn 4JohnsonSally Patient DrugIDDrug Name 1Co-codamol 2Tegretol 3Sorbitol Drug

9 Mark Dixon Page 9 People Database (with Hobbies) IDSurnameForenamesPhoneemail 1DixonMark01752 232556mark.dixon@plymouth.ac.uk 2SmithJohn01752 111111john.smith@john.smith.ac.uk 3JonesSally01752 888888sally.jones@sally.jones.com 4BloggsFred01752 123123fred.bloggs@aaaaaa.com 5AndersonGenny01752 987987genny@bbbb.cccc.com HobbyIDDescriptionPersonID 1Archery1 2Herpetology1 3Music1 4Football2 5Rugby2 6Hitting people with swords1 Hobby Person

10 Mark Dixon Page 10 Entity-relationship diagrams Each table in db –stores details of entity shown as rectangular box Relationships between tables –represent relationships between entities shown as line between entities (boxes) PersonHobby

11 Mark Dixon Page 11 Relationship Types One-to-one One-to-many Many-to-one Many-to-many –(can't be implemented in relational database) ABABABAB

12 Mark Dixon Page 12 Question: Which relationship type? IDSurnameForenamesPhoneemail 1DixonMark01752 232556mark.dixon@plymouth.ac.uk 2SmithJohn01752 111111john.smith@john.smith.ac.uk 3JonesSally01752 888888sally.jones@sally.jones.com 4BloggsFred01752 123123fred.bloggs@aaaaaa.com 5AndersonGenny01752 987987genny@bbbb.cccc.com HobbyIDDescriptionPersonID 1Archery1 2Herpetology1 3Music1 4Football2 5Rugby2 6Hitting people with swords1 Hobby Person Hobby

13 Mark Dixon Page 13 Example: Barbican Usage Add Use table for use codes:

14 Mark Dixon Page 14 Queries: Multiple Tables Add multiple tables:

15 Mark Dixon Page 15 Tutorial Exercise: Music Task 1: Create the Music database (from the lecture) with the Track and Artist tables. Task 2: Create a query to list all track titles by artists from US

16 Mark Dixon Page 16 Tutorial Exercise: Prescriptions Task 1: Create the Prescription database (from the lecture) with the Prescription, Patient, and Drug tables. Task 2: Create query to list all patients who have been prescribed Tegretol

17 Mark Dixon Page 17 Tutorial Exercises: Barbican Task 1: Download the Barbican database. Task 2: Add a new table for Use codes. Task 3: Create a query to display 1895 data with Description of use (not code). Task 4: Create a query to list all houses used for industry in 1955.


Download ppt "Mark Dixon Page 1 03 – Database Design: Multiple Tables."

Similar presentations


Ads by Google