Download presentation
Presentation is loading. Please wait.
1
Databases
2
Learning Objectives: By the end of this topic you should be able to:
describe the terms used in a relational database identify primary keys and foreign keys define relationships between entities using an entity relationship diagram for a given scenario Define
3
What is a database? What information would you record about a customer of a supermarket? What information would you record about a book in a library?
4
What is a database? a collection of data organised into a structured format.
5
What is a database? Surname: James First name: Samantha Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire a collection of data organised into a structured format.
6
What is a database? Surname: James First name: Samantha Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Brown First name: David Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire a collection of data organised into a structured format.
7
What is a database? Surname: James First name: Samantha Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Brown First name: David Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Lastler First name: David Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire a collection of data organised into a structured format.
8
What is a database? Surname: James First name: Samantha Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Brown First name: David Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Lastler First name: David Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Whitefield First name: Nina Date of Birth: Address: 16 Poppy Close Town: Southam County: Warwickshire a collection of data organised into a structured format.
9
Tables
10
Tables aka: an entity a collection of data about a certain ‘thing’
a collection of records in a relational database tables contain: rows (each row contains a record) columns (each column is a field) a relational database is made up of a number of tables a library database will have tables for Books, Members, …. the name of a table is usually capitalised: CUSTOMER(CustomerID, Forename, Surname,……, …..) Relationships
11
Records a record is a row in a database table,
contains all the data about a single item or event a customer file record will store the data about a customer records are made up of a number of fields each record contains individual items of data (in fields)
12
Fields aka: an attribute an individual data item within a record
a column in a database record, each record will be made up of a series of fields e.g. name, address etc. BOOK entity of a library will usually contain the attributes: ISBN, Title, AuthorForename, AuthorSurname, Publisher, …..
13
Primary Key every record in a table needs to be able to be identified
primary key is the field that identifies a record uniquely e.g. account number, part number, membership number hint: often has ID, Number, No, or Code at the end of the field name often underlined e.g. MEMBER(MemberID, Forename, Surname, TelNo, ….) used to create a relationship between tables used to prevent data duplication Foreign Key
14
Standard Notation e.g. for a library database:
MEMBER(MemberID, Forename, Surname, ….) BOOK(BookID, Title, Author ….) LOANS(LoanNo, MemberID, BookID, DateOut, …) Entities are written in capital letters Attributes are written with an initial capital Primary keys are underlined or labelled PK Foreign keys are overlined for OCR board or labelled FK
15
Databases A database consists of a number of t*****.
16
Databases A database consists of a number of tables.
17
Databases A database consists of a number of tables.
A table consists of a number of r******.
18
Databases A database consists of a number of tables.
A table consists of a number of records.
19
Databases A database consists of a number of tables.
A table consists of a number of records. A record consists of a number of f*****.
20
Databases A database consists of a number of tables.
A table consists of a number of records. A record consists of a number of fields.
21
Databases A database consists of a number of tables
A table consists of a number of records A record consists of a number of fields The most important field is the p****** k**.
22
Databases A database consists of a number of tables
A table consists of a number of records A record consists of a number of fields The most important field is the primary key.
23
Databases A database consists of a number of tables
A table consists of a number of records A record consists of a number of fields The most important field is the primary key A primary key contains data u***** to a record.
24
Databases A database consists of a number of tables
A table consists of a number of records A record consists of a number of fields The most important field is the primary key A primary key contains data unique to a record. Foreign Key
25
Library Database Members of a library are loaned books
26
Library Database Members of a library are loaned books Entities:
27
Library Database Members of a library are loaned books Entities:
28
Library Database Members of a library are loaned books Entities:
29
Library Database Members of a library are loaned books Entities:
LOANS Relationships
30
Library Database Members of a library are loaned books Entities:
MEMBERS(MembersID, Forename, Surname, …...) BOOKS LOANS Relationships
31
Library Database Members of a library are loaned books Entities:
MEMBERS(MembersID, Forename, Surname, …...) BOOKS(BookID, ISBN, Title, Author, …..) LOANS Relationships
32
Library Database Members of a library are loaned books Entities:
MEMBERS(MembersID, Forename, Surname, …...) BOOKS(BookID, ISBN, Title, Author, …..) LOANS(LoanID, Relationships
33
Library Database Members of a library are loaned books Entities:
MEMBERS(MembersID, Forename, Surname, …...) BOOKS(BookID, ISBN, Title, Author, …..) LOANS(LoanID, MembersID, Relationships
34
Library Database Members of a library are loaned books Entities:
MEMBERS(MembersID, Forename, Surname, …...) BOOKS(BookID, ISBN, Title, Author, …..) LOANS(LoanID, MembersID, BookID, Relationships
35
Library Database Members of a library are loaned books Entities:
MEMBERS(MembersID, Forename, Surname, …...) BOOKS(BookID, ISBN, Title, Author, …..) LOANS(LoanID, MembersID, BookID, LoanDate, …) Relationships
36
Foreign Key used to link the tables in a relational database.
a field in one table that is also the primary key in another often overlined (or labelled FK): MEMBERS(MembersID, Forename, Surname, …...) BOOK(BookID, ISBN, Title, Author, …..) LOANS(LoanID, MembersID, BookID, LoanDate, ….)
37
Entity Relationship Diagrams
New slideshow: ERD ERD
38
Driving School Database
39
Driving School Database
Customers
40
Driving School Database
Customers book
41
Driving School Database
Customers book lessons
42
Driving School Database
Customers book lessons in a
43
Driving School Database
Customers book lessons in a car
44
Driving School Database
Customers book lessons in a car with an
45
Driving School Database
Customers book lessons in a car with an instructor.
46
Driving School Database
Customers book lessons in a car with an instructor. Entities:
47
Driving School Database
Customers book lessons in a car with an instructor. Entities: CUSTOMERS
48
Driving School Database
Customers book lessons in a car with an instructor. Entities: CUSTOMERS LESSONS
49
Driving School Database
Customers book lessons in a car with an instructor. Entities: CUSTOMERS LESSONS CAR
50
Driving School Database
Customers book lessons in a car with an instructor. Entities: CUSTOMERS LESSONS CAR INSTRUCTOR
51
Restaurant Database Customers make reservations.
Orders are made of menu items and are given to the waiter. Entities: CUSTOMERS RESERVATION ORDER MENU_ITEMS WAITER
52
Foreign Key used to link the tables in a relational database.
a field in one table that is also the primary key in another often overlined: MEMBER(MemberID, Forename, Surname, …...) BOOK(BookID, ISBN, Title, …..) LOANS(LoanID, MemberID, BookID, LoanDate, ….)
53
Relationships Members of a library are loaned books Entities: MEMBERS
LOANS
54
Relationships MEMBERS
55
Relationships MEMBERS LOANS
56
Relationships MEMBERS LOANS
57
Relationships MEMBERS LOANS BOOKS
58
Relationships MEMBERS LOANS BOOKS
59
Relationships MEMBERS MemberID LOANS LoanID BOOKS BookID
60
Relationships MEMBERS MemberID LOANS LoanID MemberID BOOKS BookID
61
Relationships MEMBERS LOANS BOOKS MemberID LoanID MemberID BookID
62
Relationships MEMBERS LOANS BOOKS MemberID Forename Surname PostCode
LoanID MemberID BookID DateOut BOOKS BookID Title Author ISBN
63
Relationships MEMBERS LOANS BOOKS
MemberID Forename Surname PostCode LOANS LoanID MemberID BookID DateOut BOOKS BookID Title Author ISBN MEMBERS(MemberID, Forename, Surname, PostCode) BOOKS(BookID, Title, Author, ISBN) LOANS(LoanID, MemberID, BookID, DateOut) Relationships Primary Key
64
Foreign Key used to link the tables in a relational database.
a field in one table that is also the primary key in another often overlined: MEMBER(MemberID, Forename, Surname, …...) BOOK(BookID, ISBN, Title, …..) LOANS(LoanID, MemberID, BookID, LoanDate, ….)
65
Relationships (SBD 2012) Outlets have visits for different types of inspection Entities: OUTLET INSPECTIONTYPES INSPECTIONVISITS
66
Exam question:
67
Exam question:
68
Exam question:
69
Exam question:
70
Relationships
71
Relationships A primary key is a ***** that contains a ****** item of **** that identifies a particular ******.
72
Relationships A primary key is a ***** that contains a ****** item of **** that identifies a particular ******. A foreign key is the ******* *** from another e***** and is used to l*** the t****s together forming a ************.
73
Relationships the links between entities in a relational database:
74
Relationships the links between entities in a relational database:
75
Relationships the links between entities in a relational database:
there are three degrees of relationship between entities:
76
Relationships the links between entities in a relational database:
there are three degrees of relationship between entities: one-to-one,
77
Relationships the links between entities in a relational database:
there are three degrees of relationship between entities: one-to-one, one-to-many,
78
Relationships the links between entities in a relational database:
there are three degrees of relationship between entities: one-to-one, one-to-many, many-to-many.
79
Relationships
80
One-to-One Relationship
81
One-to-Many Relationship
82
Many-to-Many Relationship
83
Many-to-Many Relationship
usually broken down into two 1:many relationships using a link table
84
Many-to-Many Relationship
85
Exam question: A company stores details of customers and bookings in a database. Two of the entities in the database are CUSTOMER and BOOKING. What is the relationship between CUSTOMER and BOOKING? [1]
86
Exam question:
87
Exam question:
88
Exam Question: A company manufactures electronic tills for use in shops. The company has decided to write a database to store information about its sales. The entities that will be used in the database are: CUSTOMER: A list of the customers that have purchased tills from them TILL: A list of tills that are produced by the company SALESPERSON: The member of the company who was responsible for the sale ORDER: The details of the orders placed by the company ORDER_LINES: The details of the individual tills that make up each order Draw the Entity Relationship Diagram (ERD) making sure that the degree of each relationship is identified [6]
89
Relationships to link records in different tables
making sure data is not duplicated by ensuring referential integrity reduces storage space required since data is not duplicated
90
Entity-Relationship diagrams
E-R diagram (ERD),
91
Entity-Relationship diagrams
E-R diagram (ERD), a graphical representation of the entities and the relationships between them,
92
Entity-Relationship diagrams
E-R diagram (ERD), a graphical representation of the entities and the relationships between them, from Access
93
Entity-Relationship diagrams
E-R diagram (ERD), a graphical representation of the entities and the relationships between them, from Access manually drawn CUSTOMER BOOKINGS STAFF
94
Entity Relationship diagram
Members of a marching band who are loaned instruments and attend events:
95
Standard Notation Entities are written in capital letters
Attributes are written with an initial capital Primary keys are underlined or labelled PK Foreign keys are overlined for OCR board or labelled FK
96
Standard Notation Entities are written in capital letters
Attributes are written with an initial capital Primary keys are underlined or labelled PK Foreign keys are overlined for OCR board or labelled FK e.g. for a library database: MEMBER(MemberID, Forename, Surname, ….) BOOK(BookID, Title, Author ….) LOANS(LoanNo, MemberID, BookID, DateOut, …)
97
Referential Integrity
every foreign key must have a related primary key value e.g. for a customer ID in a hire table there must be the same customer (ID) in the customer table you can’t hire something to a non-existent customer! if a customer record is deleted then all ‘hires’ by the deleted cusomer are removed. ensures no redundant data is stored
98
Duplicate Data more than 1 copy of a data record
e.g. customer’s data entered & stored twice data taking up more storage space than necessary possible data inconsistency 2 different copies of the data
99
Entity Relationship Diagram (SBD 2012)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.