Download 2 nd half - Department of Computer Science and Information Systems

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to Computer Systems
Lecturer: Steve Maybank
Department of Computer Science and Information Systems
sjmaybank@dcs.bbk.ac.uk
Autumn 2015
Week 10b: Relational Databases
1st December 2015
Birkbeck College, U. London
1
Definition of a Database

A collection of data with internal links
that make the information accessible
from a variety of perspectives.
1st December 2015
Brookshear, Section 9.1
2
Very Large Databases
Facebook
357 PB
CERN (Higgs Boson)
200 PB
Microsoft Hotmail
150 PB
German Climate Computing
Centre (DKRZ)
60 PB
1PB=1015 Bytes
= 0.15MB for
every person on
Earth
See en.wikipedia.org/wiki/Petabyte
1st December 2015
Birkbeck College
3
Different Perspectives
In an employee database, list
 All employees in personnel
 All job titles in Accounts
 All employees under 30
 All departments with 50 or more
employees
…
1st December 2015
Brookshear, Section 9.2
4
File Oriented Information System
Customer
records
Customer
service
dept
1st December 2015
Payroll
records
Payroll
dept
Brookshear, Section 9.1
Employee
records
Employee
dept
5
Database Oriented Information System
Customer
service
dept
Integrated
database
Employee
dept
Payroll
dept
1st December 2015
Brookshear, Section 9.1
6
Database Model



User’s concept of the database
Eg. in a relational database model the user
sees all the data in tables
The actual storage and management of the
data may not correspond to the database
model.
1st December 2015
Brookshear, Section 9.1
7
Table in a Relational Database
Customer
Num
1st December 2015
Name
Address
102
Sperry
1 The Lane
103
Univac
15 Retail Road
54
Honeywell
205 North Street
Brookshear, Section 9.2
8
User Interface
1st December 2015
Birkbeck College
9
Layers in a Database Implementation
User


Applications
Software
DBMS
Actual
data
Applications Software: user interface, including
implementation of the database model.
Database Management System: updates the
database and supplies data to the applications
software.
1st December 2015
Brookshear, Section 9.1
10
Advantages of Splitting AS from DBMS

The user sees only the database model. The true
complexity of the database is hidden.

The DBMS can be changed without affecting users.

The AS can be tailored for different groups of users.

Easier access control because all access is through a
single DBMS.
1st December 2015
Brookshire, Section 9.1
11
Database Consisting of a Single File
Order
num
Customer
name
Customer
address
Price
Due
date
Product
37
Sperry
1 The Lane
£1000 1.7.06 Plate
43
Univac
15 Retail Road £2000 5.5.06 Case
20
Honeywell
205 North
Street
£3400 2.4.06 Panel
If a customer has no orders, then all information about that
customer is lost.
1st December 2015
cf. Brookshear, Section 9.1
12
Relational Model
Table
heading
Table




Customer
Num
Name
Address
102
Sperry
1 The Lane
103
Univac
15 Retail Road
54
Honeywell
205 North Street
All data is organised into rectangular tables called relations.
Each row (or tuple) is a single data item.
Each column is an attribute, taking values in a specified
domain.
The table heading is not a row in the table.
1st December 2015
Brookshear, Section 9.2
13
Advantages and Disadvantages
Advantages:
 When a table is updated, the information in the other
tables is unchanged
 Information is not duplicated.
Disadvantage:
 Once the relations are established they cannot be
easily changed.
1st December 2015
Brookshear, Section 9.2
14
Relational Database
Order
Num
Customer
Num
Price
Due
date
Product
37
102
£1000
1.7.06
Plate
43
103
£2000
5.5.06
Case
20
54
£3400
2.4.06
Panel
Customer Name
Num
Address
102
Sperry
1 The Lane
103
Univac
15 Retail
Road
54
Honeywell
205 North
Street
Order file
Customer file
What is the address of Sperry?
What is the total value of the orders placed with Honeywell?
How many different products are there on order?
How many different products are there?
1st December 2015
Birkbeck College
15
Table Structure



Each table should correspond to a single concept or
task
Each row of a table should be uniquely identified by a
key
Avoid including the same information in different
tables
1st December 2015
Brookshear, Section 9.2
16
Keys



Primary key: an attribute whose value
uniquely identifies a tuple.
Composite key: a minimal set of
attributes whose values together
uniquely identify a tuple
Foreign key: set of attributes pointing
to a primary key or a composite key in
another table.
1st December 2015
cf. Brookshear, Section 9.2
17
Examples of Keys
Order
Num
Customer
Num
Price
Due
date
Product
37
102
£1000
1.7.06
Plate
43
103
£2000
5.5.06
Case
20
54
£3400
2.4.06
Panel
Customer Name
Num
Address
102
Sperry
1 The Lane
103
Univac
15 Retail
Road
54
Honeywell
205 North
Street
Order file
Customer file
Primary keys: Order Num in the Order file,
Customer Num in the Customer file
Foreign key: Customer Num in the Order file
1st December 2015
Birkbeck College
18
Problem

Find the names of all customers who have ordered products
with a total value of £3000 or less.
1st December 2015
Birkbeck College
19
Lossless Decomposition


In lossless decomposition a relation
(table) is decomposed into smaller
relations without loss of information.
Aim: to produce a better table
structure.
1st December 2015
Brookshear, Section 9.2
20
Original Relation
Order Customer Price Due Product Name Address
no.
no.
date
37
102
£1000 1.7.06 Plate
Sperry
1 The
Lane
43
103
£2000 5.5.06 Case
Univac
15 Retail
Road
20
54
£3400 2.4.06 Panel
Honeywell 205
North
Street
Original table
1st December 2015
cf Brookshear, Section 9.2
21
Example of a Lossless Decomposition
Order Custo Price Due Product
no.
mer
date
no.
37
43
20
102
103
54
£1000
£2000
£3400
1.7.06
5.5.06
2.4.06
Plate
Case
Panel
Customer
no.
Name
102
Sperry
1 The
Lane
103
Univac
15 Retail
Road
54
Honeywell
205
North
Street
Order file
1st December 2015
Address
Customer file
Brookshear, Section 9.2
22
Original Relation
Empl
Id
1st December 2015
Job
Title
Dept
203
Assistant
Finance
17
Manager
Finance
18
Manager
Planning
Brookshear, Section 9.2
23
Example of a Lossy Decomposition
Empl Job Title
Id
Job Title
Dept
203
Assistant
Assistant
Finance
17
Manager
Manager
Finance
18
Manager
Manager
Planning
1st December 2015
Brookshear, Section 9.2
24
Problem 2
Name
What is the difference in the
information supplied by the single
relation
Department Tel.No.
Jones
Sales
555-2222
Smith
Sales
555-3333
Baker
Personnel 555-4444
and the two relations
Name
Department
Department
Jones
Sales
Sales
555-2222
Smith
Sales
Sales
555-3333
Baker
Personnel
Personnel 555-4444
1st December 2015
Tel.No.
Brookshear, Ch. 9, Problem 28
25
Problem 3


Let R(X,Y,Z) be a relation with
attributes X, Y, Z, and let R(X,Y) and
R(Y,Z) be relations obtained by
decomposing R(X,Y,Z).
Prove that if Y is a key for R(X,Y), then
the decomposition is lossless.
See S. Sumathi and S. Esakkirajan, Fundamentals of relational
database management systems.
1st December 2015
Birkbeck College
26
Related documents