240 likes | 419 Views
A2 Computing. Lesson Databases - Introduction. Aims and Objectives. To understand what a relational database is To understand how to design a relational database using ER modelling To be able to construct a model of a new database using this technique. What is a database?.
E N D
A2 Computing Lesson Databases - Introduction
Aims and Objectives • To understand what a relational database is • To understand how to design a relational database using ER modelling • To be able to construct a model of a new database using this technique
What is a database? • A structured collection of data • Data is usually stored in tables Surname: James First name: Samantha Date of Birth: 20.12.89 Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Brown First name: David Date of Birth: 20.12.89 Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Lastler First name: David Date of Birth: 20.12.89 Address: 16 Poppy Close Town: Southam County: Warwickshire Surname: Whitefield First name: Nina Date of Birth: 21.02.76 Address: 16 Poppy Close Town: Southam County: Warwickshire
Flat Files A flat file is a database held in a single file consisting of one table. Record Field File
Flat File problems • There are a number of problems using flat files where everything is stored in one table • data is often repeated in several different places • as a result, updating of data is time consuming and often inaccurate • data entry is time consuming and prone to errors
Using multiple tables • Using a database with multiple tables (a relational database) means that data can be separated into a more structured design • Data between tables is linked so that it is accessed only when required ( a relationship is established) • Advantages • Reduces the repeating of data (redundant data) • Reduces error on updating and inputting of data • Increases the reliability of the database (data integrity) • Increases speed of data retrieval
Building a database • Before a relational database can be built it needs to be designed so it works effectively and efficiently • The data requirements are carefully analysed • A data model is built • a method of describing the data, the structure and how it is interrelated, the constraints that apply • You will be learning the process………
Entity-relationship modelling • An entity is: • An object, person or a thing of interest represented in a database. • Customers, Employees, Products, Orders. • Each entity will normally be represented by a table in the relational database. • Entity names are normally in the singular • Customer not Customers
Entity-relationship modelling • An attribute is: • The information held about an entity. • e.g. Customer attributes: • Surname • Forname • Address • Phone number • Attributes are normally stored in fields.
Car model Car Colour Registration number Date of Registration Cost Attribute Entity Attribute Attribute Attribute Attribute Question - Entity or Attribute?
Question • A database is to store details of the following • students at college • A level courses • Write down suitable entity names for these • For each entity write down possible attributes • Draw the database table that would represent these details
Entity relationships • The link between two entities is called a relationship. • Often shown as a Diagram. Entity Relationship Diagrams (ER Diagrams) CAR OWNER
MAN Is married to WOMEN MOTHER CHILD PATIENT STUDENT ORDER TREATMENT CLASS PRODUCT Types of relationships • One to one (1:1) • One to many (1:n or 1:*) • Many to Many (n:n*:*)
OWNER CAR CAR OWNER Question • A car has one registered owner with the DVLA • One person may own several vehicles • Draw an entity-relationship diagram to represent this is owner of is owned by
BLIND PERSON GUIDE DOG GUIDE DOG BLIND PERSON Question • It is possible for a blind person to be given one guide dog • A guide dog will look after just one blind person • Draw the entity-relationship diagram to represent this keeps guides
ITEM ORDER ORDER ITEM Question • An item can be ordered by a customer • A customer may order as many items as is needed • An item may appear on orders made by different customers • Draw an entity-relationship diagram to represent the item and the order appears on consists of
ORDER ORDERITEM ORDER ITEM ITEM Dealing with many-to many relationships • Many-to-many relationships cannot be implemented easily in a database • It is important to break up many to many relationships by creating an extra entity New Entity
Question • A library lends out books to borrowers • Each borrower may borrow several books • There may be more than one copy of a book • Each book title is identified by its ISBN • Each book copy is identified by a unique number • Draw the entity-relationship diagram to represent this system
Answer BOOKTITLE has BORROWER BOOKCOPY
Answer BOOKTITLE has BORROWER BOOKCOPY makes of LOAN
Summary • A relational database can be modelled using an entity-relationship diagram • There are four degrees of relationships • one to one (1:1) • many to one (n:1) • one to many (1:n) • many to many (n:n) • many-to-many relationship should be broken up as they cannot easily be represented in a database
Glossary Database: a structured collection of data Data model: a method of describing the data, it’s structure and the way it is interrelated Entity: an object or thing of interest about which data is recorded Attribute: A piece of data recorded about an entity Relationship: an association or link between two entities