Download presentation
Presentation is loading. Please wait.
Published byBlaze Stewart Modified over 8 years ago
1
Lesson Objectives By the end of this lesson you will be able to: 1.Assign appropriate primary keys/key fields 2.Identify foreign keys in different tables/files 3.Describe the key term relationships
2
Student number SurnameFirst name D.O.B.AddressPhone number IllnessesAllergiesDoctor 1042JonesEmma05/04/95123 High Street 01234 765555 NutsDr. Brown 1043SmithLouise12/08/9545 Low Road 01234 688674 DiabetesDr. Green 1044WhiteSimon26/06/9567 Middle Lane 01234 984532 Wasp stings Dr. Yellow Recap of Key Terms… File – collection of related records Record – all data relating to one thing or person Field – a single item of data
3
Continued… What is a key field? A unique piece of data in a record also known as a primary key. What is a flat file database? A database which consists of only one table. What is a relational database? A database which consists of more than one table.
4
Primary Key IDTitleDirectorLead ActorCertificate 01The Shawshank RedemptionFrank DarabontTim Robbins15 02The GodfatherFrancis Ford CoppolaMarlon Brando15 03InceptionChristopher NolanLeonardo DiCaprio12A 04Pulp FictionQuentin TarantinoJohn Travolta18 05Schindler's ListSteven SpielbergLiam Neeson15 Primary Key A field in the table which allows each record to be uniquely identified. Databases only work if each record is different. Primary Keys sort this out! E.g. ID, Car Number Plate, National Insurance Number.
5
Suitable or Not… In your books write down whether or not each of the following would be suitable primary keys? Date of Birth – Employee Number – Student ID – Surname – Postcode – Car Number Plate – Suitable Not Suitable Suitable
6
Example – A Flat File Database Student Student Number Surname Forename Date of Birth Tutor Group Staff Number Staff Title Staff Initial Staff Surname Which is the primary key? If students are in the same tutor group which fields would contain data that would be repeated? See Student Flat File Database Example
7
Linking Tables In relational databases the same data is stored more efficiently in more than one table. These tables are linked together. This helps save time as you no longer need to type in the same data over and over again known as reducing data redundancy. Students Student Number Surname Forename Date of Birth Tutor Group Tutor Groups Tutor Group Staff Number Tutors Staff Number Staff Title Staff Initial Staff Surname Student Student Number Surname Forename Date of Birth Tutor Group Staff Number Staff Title Staff Initial Tutor Surname
8
Relationships To link tables together there needs to be the same field in each table, which is usually the primary key. Students Student Number Surname Forename Date of Birth Tutor Group Tutor Groups Tutor Group Staff Number Tutors Staff Number Staff Title Staff Initial Staff Surname Which are the primary keys?
9
Foreign Keys A foreign key is a field that is a primary key of another table. Foreign keys are used to establish relationships between tables. In the example – the field Tutor Group would be the key field or primary key in the Tutor Groups table and a foreign key in the Students table. Students Student Number Surname Forename Date of Birth Tutor Group Tutor Groups Tutor Group Staff Number Primary Key Foreign Key
10
Relationships To link the Students table to the Tutor Groups table we can use the Tutor Group field as it is in both tables. Similarly, the Tutor Groups table and Staff table can be linked through the Staff ID field. Students Student Number Surname Forename Date of Birth Tutor Group Tutor Groups Tutor Group Staff ID Staff Staff ID Staff Title Staff Initial Staff Surname Which are the foreign keys? Primary Keys See Student Relational Database Example
11
Task Create the database structure for a DVD Rental Shop. You will need to store the following information and assign appropriate primary and foreign keys. Length of FilmForename Year ReleasedFilm Title E-mailDate Rented RatingAddress Rental PriceAge SurnameDate Returned Phone NumberFilm Genre GenderPostcode Step 1 – Divide the fields up into separate categories – there will be 3 tables.
12
The Tables Customer Surname Forename Address Postcode Telephone Number E-mail Age Gender Film Film Title Rating Film Genre Date Released Length of Film Rental Price Rentals Date Rented Date Returned Step 2 – Add a primary key to each table. What would be appropriate primary keys? Customer CustomerID Surname Forename Address Postcode Telephone Number E-mail Age Gender Film FilmID Film Title Rating Film Genre Date Released Length of Film Rental Price Rentals RentalID Date Rented Date Returned
13
Linking the Tables Customer CustomerID Surname Forename Address Postcode Telephone Number E-mail Age Gender Film FilmID Film Title Rating Film Genre Date Released Length of Film Rental Price Rentals RentalID Date Rented Date Returned Step 3 – Link the tables together by assigning appropriate foreign keys.
14
Linking the Tables Customer CustomerID Surname Forename Address Postcode Telephone Number E-mail Age Gender Film FilmID Film Title Rating Film Genre Date Released Length of Film Rental Price Rentals RentalID Date Rented Date Returned CustomerID FilmID This now means the DVD shop can clearly identify which films have been rented by each of their customers without having to repeat the same information.
15
The same but different… Looking at these two structures which one is better and why? Customer CustomerID Surname Forename Address Postcode Telephone Number E-mail Age Gender Date Rented Date Returned Film Title Rating Film Genre Date Released Length of Film Rental Price Customer CustomerID Surname Forename Address Postcode Telephone Number E-mail Age Gender Film FilmID Film Title Rating Film Genre Date Released Length of Film Rental Price Rentals RentalID Date Rented Date Returned CustomerID FilmID
16
Exam Question
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.