19 – Databases: Multiple Tables

Slides:



Advertisements
Similar presentations
Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple.
Advertisements

Mark Dixon Page 1 23 – Object Oriented Programming in PhP.
GCSE Computing#BristolMet Session Objectives# 21 MUST describe methods of validating data as it is input. SHOULD explain the use of key fields to connect.
Mark Dixon Page 1 05 – Database Design: Sub-forms.
Mark Dixon Page 1 04 – Database Design: Forms. Mark Dixon Page 2 Session Aims & Objectives Aims –To allow easier data entry using forms Objectives, by.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.
Mark Dixon Page 1 03 – Database Design: Multiple Tables.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 SOFT – Module Introduction.
Designing a Database Unleashing the Power of Relational Database Design.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Entity-relationship diagrams.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 18 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon Page 1 20 – Modular Design in ASP. Mark Dixon Page 2 Session Aims & Objectives Aims –Highlight modular design techniques in ASP Objectives,
Mark Dixon, SoCCE SOFT 131Page 1 18 – Structured Query Language.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 19 – Databases: Multiple Tables.
Relational Databases What is a relational database? What would we use one for? What do they look like? How can we describe them? How can you create one?
Mark Dixon 1 20 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 5 – Persistent data storage: relational databases.
2.3 Organising Data for Effective Retrieval
Unit 18: Database Modelling
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Banner and the SQL Select Statement: Part Three (Joins) Mark Holliday Department of Mathematics and Computer Science Western Carolina University 4 November.
Mark Dixon Page 1 21 – Persistent data storage: relational databases and MySQL.
Mark Dixon 1 05 – JSP Databases: Multiple Tables.
Mark Dixon 1 06 – JSP Databases: Multiple Tables.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
Mark Dixon 1 21 – Databases: Multiple Tables. Mark Dixon 2 Questions: Databases How many records are in the following table? How many fields does the.
Mark Dixon 1 21 – Databases: Multiple Tables and Writing Data.
Lesson 2: Designing a Database and Creating Tables.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Web applications: Databases & ASP.
MIS2502: Data Analytics Relational Data Modeling
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.
Plan the progression for the databases topic.
Mark Dixon, SoCCE SOFT 131Page 1 14 – Databases: Multiple Tables.
U:/msu/course/cse/103 Day 08, Slide 1 Debrief Homework What problems arose in trying to import the data from Classical_Music.xls?
For more course tutorials visit CIS 336 All iLabs Week 1 to Week 7 Devry University CIS 336: All iLabs Week 1 to Week 7: Devry University.
INFO 340 Lecture 3 Relational Databases. Based on the relational model, grounded in mathematic set theories. Three basic elements: Relation, Tuple, and.
28 Database Theory 28. Database Theory We have looked at the basics of how databases work: Database Tables A A Relational Databases C C Types of Data.
PGCE Computer Science/ICT Progression in Databases Alex Hadwen-Bennett.
Our world depends on databases
DBM 380 AID Focus Dreams/dbm380aid.com
SQL – join.
Relational Model.
18 – Databases: Structured Query Language
MIS2502: Data Analytics Relational Data Modeling
DBM 380 aid Education Begins/dbm380aid.com
CIS 155 Table Relationship
Database Concepts Relational Databases Start ….
Databases A brief introduction….
CIS 336 strCompetitive Success/tutorialrank.com
CIS 336 str Education for Service-- tutorialrank.com.
Teaching slides Chapter 8.
Relational Queries (query 12) Display vendor contact info (contact person and phone number) for inventory products (relationship query) Query: Inventory.
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Advanced Database Concepts: Reports & Views
17 – Persistent data storage: relational databases and ADO
Lecture 7 Tuesday 4/12/2018 Slides from A. Ballatore, Geography
New Perspectives on Microsoft
Information system analysis and design
Presentation transcript:

19 – Databases: Multiple Tables

Session Aims & Objectives 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 generate SQL statements to (temporarily) join tables, and use these in your code

Flat files: Data Duplication Field Track Track Title Artist Name Country Paranoid Black Sabbath UK Falling in Love Aerosmith US Pink Love in an Elevator Smooth Criminal Alien Ant Farm Meaning of Life Disturbed The Game Voices Down with the Sickness Record

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

Relations (tables) Primary Key Foreign Key Track Track Title Artist ID Paranoid 1 Falling in Love 2 Pink Love in an Elevator Smooth Criminal 3 Meaning of Life 4 The Game Voices Down with the Sickness Artist Artist ID Artist Name Country 1 Black Sabbath UK 2 Aerosmith US 3 Alien Ant Farm 4 Disturbed Primary Key Foreign Key

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 Date Surname Forenames Drug Name 6 Jan 04 Jones Alison Co-codamol 11 Jan 04 Smith Bob Tegretol 18 Jan 04 Hope John 5 Feb 04 Johnson Sally 8 Feb 04 10 Feb 04 Sorbitol

Question: Solution Patient PatientID Surname Forenames 1 Jones Alison 2 Smith Bob 3 Hope John 4 Johnson Sally Prescription Date PatientID DrugID 6 Jan 04 1 11 Jan 04 2 18 Jan 04 3 5 Feb 04 4 8 Feb 04 10 Feb 04 Drug DrugID Drug Name 1 Co-codamol 2 Tegretol 3 Sorbitol

People Database (with Hobbies) Person ID Surname Forenames Phone email 1 Dixon Mark 01752 232556 mark.dixon@plymouth.ac.uk 2 Smith John 01752 111111 john.smith@john.smith.ac.uk 3 Jones Sally 01752 888888 sally.jones@sally.jones.com 4 Bloggs Fred 01752 123123 fred.bloggs@aaaaaa.com 5 Anderson Genny 01752 987987 genny@bbbb.cccc.com Hobby HobbyID Description PersonID 1 Archery 2 Herpetology 3 Music 4 Football 5 Rugby 6 Hitting people with swords

Entity-relationship diagrams Each table in db stores details of entity shown as rectangular box Person Hobby Relationships between tables represent relationships between entities shown as line between entities (boxes)

Relationship Types One-to-one One-to-many Many-to-one Many-to-many (can't be implemented in relational database) A B A B A B A B

Question: Which relationship type? Person ID Surname Forenames Phone email 1 Dixon Mark 01752 232556 mark.dixon@plymouth.ac.uk 2 Smith John 01752 111111 john.smith@john.smith.ac.uk 3 Jones Sally 01752 888888 sally.jones@sally.jones.com 4 Bloggs Fred 01752 123123 fred.bloggs@aaaaaa.com 5 Anderson Genny 01752 987987 genny@bbbb.cccc.com Hobby HobbyID Description PersonID 1 Archery 2 Herpetology 3 Music 4 Football 5 Rugby 6 Hitting people with swords Person Hobby

SQL: Joining tables SELECT * FROM [Person], [Hobby]; Two tables Cartesian set (all record combinations):

SQL: Joining tables Two tables SELECT * FROM [Person], [Hobby] WHERE [Person].[ID] = [Hobby].[PersonID]; Matching records ID Surname Forenames Phone email HobbyID Description PersonID 1 Dixon Mark 01752 232556 mark.dixon@plymouth.ac.uk Archery 2 Herpetology 3 Music 6 Hitting people with swords Smith John 01752 111111 john.smith@john.smith.ac.uk 4 Football 5 Rugby

SQL: Joining tables SELECT [ID], [Surname] FROM [Person], [Hobby] WHERE [Person].[ID] = [Hobby].[PersonID]; ID Surname 1 Dixon 2 Smith

SQL: DISTINCT records SELECT DISTINCT [ID], [Surname] FROM [Person], [Hobby] WHERE [Person].[ID] = [Hobby].[PersonID]; ID Surname 1 Dixon 2 Smith

SQL: More Loads more: Have a look at: group by aggregate functions: average, count inner joins outer joins (left and right) Have a look at: http://www.w3schools.com/sql/sql_join.asp

Tutorial Exercise: Music Task 1: Create the Music database (from the lecture) with the Track and Artist tables. Task 2: Create a web page to display a list of Artists. Task 4: Change that web page, so that each artist name is a link to another page, which displays all the tracks by that artist. Hint: Use query strings to pass the artist ID between pages.

Tutorial Exercise: Prescriptions Task 1: Create the Prescription database (from the lecture) with the Prescription, Patient, and Drug tables. Task 2: Create a web page to display a list of Drugs. Task 3: Change that web page, so that each drug name is a link to another page, which displays all the people using that drug.