Link tables and keys Access/IPS Walsall College of Arts & Technology.

Slides:



Advertisements
Similar presentations
Data Design The futureERD - CardinalityCODINGRelationshipsDefinition.
Advertisements

ISP 121 Access Normalization and Relationships. Normalization Say we’re operating a pet day-care and we need to keep information on our pets/customers.
Tutorial 1 Entity Relationship Modelling. Entities and what they mean One-to-many Header-Items Invoice/ Invoice Items Customer/ Customer- Branch Bidirectional.
Entity-Relationship Model and Diagrams (continued)
LIS 557 Database Design and Management William Voon Michael Cole Spring '04.
Database Design Chapter 3.
Lecture 9 Handling Many to Many Relationships INFO 1408 Database Design Concepts.
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?
WJEC Applied ICT Databases – Attributes & Entities Entities A database contains one or more related tables. Each table holds all of the information.
Page 1 ISMT E-120 Introduction to Microsoft Access & Relational Databases The Influence of Software and Hardware Technologies on Business Productivity.
Entity Relationship Diagram Farrokh Alemi Ph.D. Francesco Loaiza, Ph.D. J.D. Vikas Arya.
 An entity-relationship (ER) diagram is a specialized graphic that illustrates the interrelationships between entities in a database.  An Entity Relationship.
Page 1 ISMT E-120 Desktop Applications for Managers Introduction to Microsoft Access.
© Jalal Kawash 2010 Databases & Data Modelling Peeking into Computer Science.
Bite sized training sessions: Data Modelling – Part 1 of 2 Data Model Diagrams Feb 2011 Prepared by Guy Beauchamp Group Projects & IT.
Module Title? DBMS E-R Model to Relational Model.
The Teacher Computing Database Design CP4 Revision.
Database Systems Marcus Kaiser School of Computing Science Newcastle University.
Principles of Database Design, Part II AIMS 2710 R. Nakatsu.
Relational databases and third normal form As always click on speaker notes under view when executing to get more information!
G057 - Lecture 02 Introduction To Database System Concepts Mr C Johnston ICT Teacher
MIS 301 Information Systems in Organizations Dave Salisbury ( )
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
© Jalal Kawash Databases & Data Modelling Peeking into Computer Science.
Applicants Please use speaker notes for additional information!
Chapter 5: Data Types (2013) Revision Candidates should be able to know: Identify different data types? Key terms: File, record, field and key field Database.
1 Information Retrieval and Use Data Analysis & Data Modeling, Relational Data Analysis and Logical Data Modeling Geoff Leese September 2009.
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
CPSC 203 Introduction to Computers Tutorial 03 & 29 By Jie (Jeff) Gao.
What we’ve learnt Doc 5.69 Doc 5.70 Section 1-3. A simple database Related objects Tables hold the data Forms, reports, queries to access the data.
1.  An introduction to data modelling  The purpose of data modelling  Modelling data relationships 2.
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Database Beginnings. Scenario so far In our scenario we have people registering for training sessions. –The data about the training sessions was placed.
IE 423 – Design of Decision Support Systems Data modeling and database development.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Physical.
Introduction to Database using Microsoft Access 2013 Part 7 November 19, 2014.
M1G Introduction to Database Development 4. Improving the database design.
Access Review. Access Access is a database application A database is a collection of records and files organized for a particular purpose Access supports.
Database Management Systems MIT Lesson 02 – Database Design (Entity Relationship Diagram) By S. Sabraz Nawaz.
An Entity Relationship (ER) Diagram is a graphic that shows the interrelationship between entities in a database.
Description and exemplification of entity-relationship modelling.
Btec National - Advanced Databases 1 Advanced Databases Entity Relationship Diagrams.
Jozef Kuper.  Describe a Database  Entities  Atributes  Relationships.
In this session, you will learn to: Map an ER diagram to a table Objectives.
ENTITY RELATIONSHIP DIAGRAM ENTITY RELATIONSHIP DIAGRAM IS A SPECIALIZED GRAPHIC THAT ILLUSTRATES THE INTERRELATIONSHIPS BETWEEN ENTITIES IN A DATABASE.
Databases Illuminated Chapter 3 The Entity Relationship Model.
Quiz questions. 1 A data structure that is made up of fields and records? Table.
Database Design Normalisation. Last Session Looked at: –What databases were –Where they are used –How they are used.
Lesson 2: Designing a Database and Creating Tables.
Chapter 56 Relational Database Design Compiled by Eddie Moorcroft.
Databases and E-R Diagrams Access/IPS Walsall College of Arts & Technology.
Entity relationship diagram Name: Quian Crosby Form:6AQ Subject: Information Technology Teacher: Ms. D. Anderson.
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
Sample Table Standard Notation Entity name in uppercase
Btec National - IT SYSTEMS ANALYSIS AND DESIGN 1 IT Systems Analysis and Design Entity Relationship Diagrams.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
IE 423 – Design of Decision Support Systems Data modeling and database development.
Microsoft Access 2010 Chapter 11 Database Design.
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
Conversion from ER diagram to relational model 1 ER is a visual model The relational model is a matemathical model.
Teanna Clarke 6aQ What is a Entity-Relationship Diagram?  An Entity-Relationship Diagram (ERD) is a tool that graphically shows the connections among.
Data Modeling AND ER MODELS.
What Is Normalization  In relational database design, the process of organizing data to minimize redundancy  Usually involves dividing a database into.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Data.
Normalisation Unit 6: Databases. Just to recap  What is an Entity  What is an Attribute?
1 Entity Relationship Approach u Top-down approach to data modeling u Uses diagrams u Normalization - confirms technical soundness u Entity Relationship.
Year 12 > 13 Applied GCE ICT Unit 7 Using Database Software.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Order Database – ER Diagram
Entity relationship diagrams
Presentation transcript:

Link tables and keys Access/IPS Walsall College of Arts & Technology

November 2002Walsall College of Arts & Technology 2 What we are going to cover What are primary and foreign keys? What are primary and foreign keys? Where do we use them? Where do we use them? What is a link table? What is a link table? Why use one? Why use one? Anything else we feel like discussing Anything else we feel like discussing

November 2002Walsall College of Arts & Technology 3 Attributes – a reminder A category of information about an entity A category of information about an entity Eg. The common attributes held about a student may be: Eg. The common attributes held about a student may be: Name Name UCAS Number UCAS Number Degree scheme Degree scheme Year of study Year of study Date of Birth Date of Birth

November 2002Walsall College of Arts & Technology 4 Keys What is a key? What is a key? A key is an attribute that is always unique A key is an attribute that is always unique Why do we use them? Why do we use them? To hold data in a database, each record must be unique To hold data in a database, each record must be unique For it to be unique, the primary key must be different in each record For it to be unique, the primary key must be different in each record

November 2002Walsall College of Arts & Technology 5 Primary key example We’ll use two Computer Science students in a university database We’ll use two Computer Science students in a university database So STUDENT is the entity So STUDENT is the entity Which attributes are unique? Which attributes are unique? We could use Student Name, UCAS Number or DoB We could use Student Name, UCAS Number or DoB Student NameUCAS NumberYearDoBDegree Scheme Rufus T Firefly /11/82Computer Science Neddie Seagoon /03/1982Computer Science

November 2002Walsall College of Arts & Technology 6 Picking your primary key From the previous slide we had Student Name, UCAS number and DoB as possible primary keys From the previous slide we had Student Name, UCAS number and DoB as possible primary keys These are called candidate keys. These are called candidate keys. Let’s look closely, if the database is for the whole university is Student Name a suitable choice? Common names are likely to repeat Let’s look closely, if the database is for the whole university is Student Name a suitable choice? Common names are likely to repeat DoB is not ideal as it is not very meaningful DoB is not ideal as it is not very meaningful

November 2002Walsall College of Arts & Technology 7 ….and the winner is UCAS Number! UCAS Number! Using our own knowledge, we know that UCAS number is always unique and that every student has one Using our own knowledge, we know that UCAS number is always unique and that every student has one So we can use this to make sure every record is unique So we can use this to make sure every record is unique

November 2002Walsall College of Arts & Technology 8 Keys and E-R diagrams With a One-to-One relationship, each entity has its own primary key With a One-to-One relationship, each entity has its own primary key With a One-to-Many relationship, it is a little different With a One-to-Many relationship, it is a little different On the next slide we will examine… On the next slide we will examine…

November 2002Walsall College of Arts & Technology 9 Keys and One-to-Many Continuing the university theme Continuing the university theme STUDENT-DEGREE SCHEME is a one to many as a student can only do one degree scheme, but a degree scheme can have many students on it. STUDENT-DEGREE SCHEME is a one to many as a student can only do one degree scheme, but a degree scheme can have many students on it. If we are to show this relationship in our tables, we have to put the primary key of one of the entities in the table of the other If we are to show this relationship in our tables, we have to put the primary key of one of the entities in the table of the other

November 2002Walsall College of Arts & Technology 10 Foreign keys When we do this, the travelling primary key is called a foreign key. When we do this, the travelling primary key is called a foreign key. With a one to many, we always put the foreign key in the “many” table. With a one to many, we always put the foreign key in the “many” table. Eg. If the primary key of student is UCAS number and the primary key of Degree scheme is Degree Name, the Student table will include Degree Name as an attribute Eg. If the primary key of student is UCAS number and the primary key of Degree scheme is Degree Name, the Student table will include Degree Name as an attribute This is shown in the table we used earlier This is shown in the table we used earlier

November 2002Walsall College of Arts & Technology 11 For your convenience To save you from having to go back through the slides, here’s that table again: To save you from having to go back through the slides, here’s that table again: So the foreign key is “Degree Scheme” So the foreign key is “Degree Scheme” However, Many-to-Many relationships present more problems However, Many-to-Many relationships present more problems Student NameUCAS NumberYearDoBDegree Scheme Rufus T Firefly /11/82Computer Science Neddie Seagoon /03/1982Computer Science

November 2002Walsall College of Arts & Technology 12 Many-to-Many Unfortunately, we can’t transfer keys, because it would result in lists and duplications in both tables: Unfortunately, we can’t transfer keys, because it would result in lists and duplications in both tables: STUDENT-MODULE is a many-to-many because a student takes many modules and a module has many students on it STUDENT-MODULE is a many-to-many because a student takes many modules and a module has many students on it If we have a table for Students and a table for Modules, and if we transfer the keys we end up in a right mess… If we have a table for Students and a table for Modules, and if we transfer the keys we end up in a right mess…

November 2002Walsall College of Arts & Technology 13 That’s another fine mess… If we transfer the keys, the tables look like this: If we transfer the keys, the tables look like this: But this is impossible, because the primary key is not unique! But this is impossible, because the primary key is not unique! Student NameUCAS NumberYearDoBDegree Scheme Rufus T Firefly /11/82Programming Rufus T Firefly /11/82Databases Rufus T Firefly /11/82Networking

November 2002Walsall College of Arts & Technology 14 So what do we do? We use a link table We use a link table A link table is a purpose built table designed to break up many-to-many relationships, by converting them to one-to-many’s A link table is a purpose built table designed to break up many-to-many relationships, by converting them to one-to-many’s So what does the link table contain? So what does the link table contain? STUDENTMODULE LINK

November 2002Walsall College of Arts & Technology 15 A Link table The link table contains both primary keys (As foreign keys) The link table contains both primary keys (As foreign keys) These foreign keys are then combined to make a joint primary key These foreign keys are then combined to make a joint primary key In other words, either part of the key can repeat in the table, but a combination can’t In other words, either part of the key can repeat in the table, but a combination can’t See next slide for example See next slide for example

November 2002Walsall College of Arts & Technology 16 Link table example The link table for STUDENT-MODULE looks like this: The link table for STUDENT-MODULE looks like this: However, this would not be allowed: However, this would not be allowed: UCAS NumberModule Name Databases These are the same, but the other part of the key is different UCAS NumberModule Name Databases Databases

November 2002Walsall College of Arts & Technology 17 So what now? There is an exercise on this subject as well as the solution There is an exercise on this subject as well as the solution These are available on my personal website, the address is: These are available on my personal website, the address is: ng.htm ng.htm ng.htm ng.htm

November 2002Walsall College of Arts & Technology 18 That’s all folks That’s it for now, if you have any further questions, feel free to ask me That’s it for now, if you have any further questions, feel free to ask me If you can’t find me, you can me your questions to If you can’t find me, you can me your questions to