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.

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.
Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8.
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.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 3 1 Microsoft Office Access 2003 Tutorial 3 – Querying a Database.
SUNY Morrisville-Norwich Campus-Week 10 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Mark Dixon Page 1 07 – Reports. Mark Dixon Page 2 Session Aims & Objectives Aims –To use reports to produce more readable documents Objectives, by end.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 SOFT – Module Introduction.
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.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
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?
Lesson 32: Designing a Relational Database. 2 Lesson Objectives After studying this lesson, you will be able to:  Identify and apply principles for good.
Page 1 ISMT E-120 Desktop Applications for Managers Introduction to Microsoft Access.
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
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
Tutorial 8 Advanced Queries. Notes Switch to new database! Tutorial.08 folder Only Session 8.1 and 8.2.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
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.
Exploring Microsoft Access Chapter 4 Relational Databases, External Data, Charts, and the Switchboard.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 9 1 Microsoft Office Access 2003 Tutorial 9 – Using Action Queries, and Defining Table Relationships.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 9 – Building Links,
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.
® Microsoft Access 2010 Tutorial 9 Using Action Queries and Advanced Table Relationships.
Tutorial 9 Using Action Queries and Advanced Table Relationships.
Introduction to Database using Microsoft Access 2013 Part 7 November 19, 2014.
Microsoft Access 2013 ®® Tutorial 9 Using Action Queries and Advanced Table Relationships.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
1 The Information School of the University of Washington Dec 1fit advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.
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.
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
Extending the biogeographical model Africamuseum 6 (7?) June 2013.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.
Mark Dixon, SoCCE SOFT 131Page 1 14 – Databases: Multiple Tables.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall. 1 Skills for Success with Microsoft ® Office 2007 PowerPoint Lecture to Accompany.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
Decision Analysis Fall Term 2015 Marymount University School of Business Administration Professor Suydam Week 10 Access Basics – Tutorial B; Introduction.
18 – Databases: Structured Query Language
17 – Persistent data storage: relational databases and ADO
19 – Databases: Multiple Tables
Presentation transcript:

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 following table have? 6 4

Mark Dixon 3 Questions: SQL Write an SQL statement to display the name and land mass of all countries in Africa. SELECT Name, Land Mass FROM Country WHERE Continent = 'Africa';

Mark Dixon 4 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 a suitable primary key for a table –identify duplicated data in a single table –split that table to reduce data redundancy, using a suitable foreign key –generate SQL statements to (temporarily) join tables, and use these in your code

Mark Dixon 5 Data Duplication Look for repeating data: 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

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

Mark Dixon 7 Solution: Normalisation Part of database design Process of breaking data down (splitting) Codd –7 stages of normalisation Mathematical Difficult to apply stages Most professionals do it instinctively

Mark Dixon 8 Relations (tables) Track Title Paranoid Falling in LoveAerosmithUS PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist NameCountry Black SabbathUK

Mark Dixon 9 Relations (tables) Track Title Paranoid Falling in LoveAerosmithUS PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist ID 1 Artist Artist NameCountry Black SabbathUK IDArtist NameCountry 1Black SabbathUK

Mark Dixon 10 Relations (tables) Track Title Paranoid Falling in Love PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist ID 1 Artist IDArtist NameCountry 1Black SabbathUK AerosmithUS IDArtist NameCountry 1Black SabbathUK 2AerosmithUS 2

Mark Dixon 11 Relations (tables) Track Title Paranoid Falling in Love Pink Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist ID Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS

Mark Dixon 12 Relations (tables) Track Title Paranoid Falling in Love Pink Love in an Elevator Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist ID Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS

Mark Dixon 13 Relations (tables) Track Title Paranoid Falling in Love Pink Love in an Elevator Smooth Criminal Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist ID Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS

Mark Dixon 14 Relations (tables) Track Title Paranoid Falling in Love Pink Love in an Elevator Smooth Criminal Meaning of Life The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist ID Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS 4DisturbedUS

Mark Dixon 15 Relations (tables) Track Title Paranoid Falling in Love Pink Love in an Elevator Smooth Criminal Meaning of Life The Game VoicesDisturbedUS Down with the SicknessDisturbedUS Track Artist ID Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS 4DisturbedUS

Mark Dixon 16 Relations (tables) Track Title Paranoid Falling in Love Pink Love in an Elevator Smooth Criminal Meaning of Life The Game Voices Down with the SicknessDisturbedUS Track Artist ID Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS 4DisturbedUS

Mark Dixon 17 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 Track Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS 4DisturbedUS Primary Key Foreign Key

Mark Dixon 18 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

Mark Dixon 19 Question: Solution DatePatientIDDrugID 6 Jan Jan Jan Feb Feb Feb 0423 Prescription PatientIDSurnameForenames 1JonesAlison 2SmithBob 3HopeJohn 4JohnsonSally Patient DrugIDDrug Name 1Co-codamol 2Tegretol 3Sorbitol Drug

Mark Dixon 20 People Database (with Hobbies) IDSurnameForenamesPhone 1DixonMark SmithJohn JonesSally BloggsFred AndersonGenny01752 HobbyIDDescriptionPersonID 1Archery1 2Herpetology1 3Music1 4Football2 5Rugby2 6Hitting people with swords1 Hobby Person

Mark Dixon 21 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

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

Mark Dixon 23 Question: Which relationship type? IDSurnameForenamesPhone 1DixonMark SmithJohn JonesSally BloggsFred AndersonGenny01752 HobbyIDDescriptionPersonID 1Archery1 2Herpetology1 3Music1 4Football2 5Rugby2 6Hitting people with swords1 Hobby Person Hobby

Mark Dixon 24 SQL: Joining tables SELECT * FROM Person, Hobby; Two tables Cartesian set (all record combinations):

Mark Dixon 25 SQL: Joining tables SELECT * FROM Person, Hobby WHERE Person.ID = Hobby.PersonID; Two tables Matching records IDSurnameForenamesPhone HobbyIDDescriptionPersonID 1DixonMark DixonMark DixonMark DixonMark01752 people with swords1 2SmithJohn SmithJohn01752

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

Mark Dixon 27 Question: SQL Joining Tables Write an SQL query to join the following: Track TitleArtist ID Paranoid1 Falling in Love2 Pink2 Love in an Elevator2 Smooth Criminal3 Meaning of Life4 The Game4 Voices4 Down with the Sickness4 Track Artist IDArtist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS 4DisturbedUS

Mark Dixon 28 MS Access: SQL Query Open database Create new query Select SQL item from drop-down list SQL View DataSheet View

Mark Dixon 29 SQL: More Loads more: –group by –aggregate functions: average, count –inner joins –outer joins (left and right) Have a look at: –

Mark Dixon 30 Tutorial Exercise: Countries LEARNING OBJECTIVE: avoid duplicate data by splitting a table create a web-page to temporarily re-join and display the data Task 1: Create the Countries database (from the lecture) with the Country table. Task 2: Split the Country table to remove duplicate data. identify the duplicate data put it in a separate table create a primary key for the new table create a foreign key in the old table that links to the new table Task 3: Create a web page to display a list of Countries with associated data (Population, Land Mass, and Continent). Task 4: Add a text box and button to your page. When the user clicks the button the page should display only countries that match the continent entered in the text box (e.g. if the user types in Africa and clicks the button, only the African countries should be displayed).

Mark Dixon 31 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.

Mark Dixon 32 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.