Download presentation
Presentation is loading. Please wait.
1
3.5 Databases Relationships
2
3.5 Databases 3.5.1 Understand the characteristics of structured and unstructured data 3.5.2 Understand that data can be decomposed and organised in a structured database [tables, records, fields, relationships, keys] 3.5.3 Understand the need for and be able to use SQL statements
3
What is an entity?
4
An entity is… Not an individual item, like tomato, orange, pineapple
The entity in this case would be something like “Stock Item” Tomatoes, oranges and pineapples are instances of the entity “Stock Item” Think of some more examples of entities
5
Entities and tables Look again at tblEvent in the SportsDay database
What entity does this table hold data about?
6
Adding a field to the table
The organiser of the School Sports Day wants to add a field specifying what House each competitor is in When this is done, the Events table looks like this: Do you see any problem with this table?
7
Each entity should have its own table
An entity is a category of person or thing about which data is held As you probably spotted, there are two entities involved in tblEvent: Sports event Winners What are the weaknesses of this table structure?
8
Data redundancy The firstname, surname and House of the winner are recorded against each event Holding the same data about an entity means you are holding redundant data – more data than necessary This takes time and space in the database, and can result in inconsistencies in the data Are there two girls in Year 7 named Karen Mason?
9
Entities and attributes
Each entity has attributes associated with it. Each attribute is a field in the table which describes the entity What are the attributes of the Event entity? What are the attributes of the Winner entity? What is the unique ID of an Event?
10
Relationships between entities
There are three possible relationships between two entities One-to-one (e.g. husband and wife) One-to many (e.g. mother and children) Many-to-many (e.g. pupils and subjects) What is the relationship between Sports event and Winner (i.e. Pupil)?
11
Worksheet 2 Now try Task 1 on Worksheet 2
12
Relating two tables We need to rearrange the SportsDay database so that it has two related tables, one for Event and one for Pupil The tables will be related by means of the key field in tblPupil tblEvent EventID EventCategory EventName PreviousRecord Units DateRecordSet WinnerID WinningResult Record tblPupil PupilID FirstName Surname House DateOfBirth ContactTelephoneNo (other fields)
13
A relational database A database consisting of two or more related tables is known as a relational database The tables are related by means of a field that is common to both tables The field is a primary key in one of the tables
14
The primary key As a general rule, each table in a database needs a primary key The primary key uniquely identifies the record Which field is the primary key field in tblPupil?
15
Making the connection Which pupil won the Year 7 Girls 60m?
Which pupil won the Year 7 Boys 60m Hurdles? Which pupil won the Year 7 Girls High Jump? What House is she in?
16
Data redundancy How has this arrangement of two linked tables cured the problem of data redundancy that existed in the single table arrangement? What other potential problems are solved by having two linked tables, each holding data about one entity, rather than holding all the data in a single table?
17
Worksheet 2 Now try Task 2 on the Worksheet
18
Foreign key When you created the link between the tables tblPupil and TblEvent, the field which linked the two tables was PupilID, the key field in TblPupil In TblWinner this field was named WinnerID, but it could have been named PupilID WinnerID is called a foreign key A foreign key in a table is the field that links to the primary key in the related table
19
A many-to-many relationship
You cannot directly set up a many-to-many relationship between two entities. You need a table “in-between”, linking to both tables Link Winner Subject
20
How are the tables linked?
In Access, set up two one-to-many relationships:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.