170 likes | 300 Views
03 – Database Design: Multiple Tables. 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
E N D
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
Flat files: Data Duplication Field Record Track
Problem: Data Duplication • takes up lots of space • can become inconsistent (misspellings) • difficult to search (misspellings) • difficult to change (need to change each instance)
Relations (tables) Primary Key Foreign Key Track Artist
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
Question: Prescriptions • Identify duplication and separate: Prescription
Question: Solution Patient Prescription Drug
People Database (with Hobbies) Person Hobby
Entity-relationship diagrams Person Hobby • 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)
Relationship Types A A A A B B B B • One-to-one • One-to-many • Many-to-one • Many-to-many • (can't be implemented in relational database)
Question: Which relationship type? Person Hobby Person Hobby
Example: Barbican Usage • Add Use table for use codes:
Queries: Multiple Tables • Add multiple tables:
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
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
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.