Foundations 54
Foundations 54
• Database foundations
• Data modelling
• Properties of relational databases
• Normalisation
• Relational algebra and SQL
• Properties of OO databases
• Distributed DB, multi-DB, Web-DB
©P00482 - 2008 1
L&T infrastructure
• Oracle
• Educ software • Apache
Linux
• e-materials
• Assignment Store • Perl, CGI, DBI
• telnet, ftp, ed’s Unix • mySQL
©P00482 - 2008 2
• web-site
• cs3% /help
• books
©P00482 - 2008 3
• web-site
• cs3% /help
• books
• Virtual tutorials
©P00482 - 2008 4
/help
VIRTUAL
PROBLEMS
• web-site
TUTORIALS
• cs3% /help
• books REVISION
assignment
SQLhelp
SQLsupplement
0-operating. ORACLE.SQL
1-data_definition.SQL
SQLprogramming 2-one_table_queries.SQL
3-joining_tables.SQL
4-transaction.SQL
5-insertion.SQL
6-deletion.SQL
7-Case_Study.SQL
8-menus-and-filenames.SQL
©P00482 - 2008 5
9-sequences.SQL
MAIN SUPPORTING SOFTWARE
ORACLE v.10 (SQL & PL/SQL)
EDUCATIONAL SOFTWARE
LEAP RDMS based on algebraic processor
SQL Tutor
UNIX help
UTILITIES
puTTy remote logging
ftp file transmition between servers
pdf writer to produce files in portable format
©P00482 - 2008 6
Stanczyk, Champion & Leyton
Theory & Practice of Relational Databases (2nd ed)
• web-site Taylor & Francis, 2001
• cs3% /help http://www.theorypractice.org
• books
Date CJ
An Introduction to Database Systems (8th ed)
Addison-Wesley 2004
O'Neil/O'Neil
Databases - Principles, Programming, Performance (2nd ed)
Morgan Kaufmann 2001
Elmasri/Navathe
Fundamentals of Database Systems (3rd ed.)
Addison Wesley 2000
Korth /Silberschatz
Database System Concepts (3rd ed)
McGraw Hill 2001
©P00482 - 2008 7
DATA DATA DATA
COLLECTION COLLECTION COLLECTION
©P00482 - 2008 8
• Redundancy of data
• Non-interchangeability of data
• Non-interchangeability of processes
• Uncontrolled expansion
©P00482 - 2008 9
DATA MANAGEMENT ROUTINES
all communication
database physical representation
user/program
CENTRAL STORE OF DATA
+
DATA DESCRIPTION
solely through
the DataBase Management System
i.e.
every activity in the system, such as:
RETRIEVAL ROUTINES
• defining and modifying database
objects
• inserting, deleting and updating
• retrievals
is controlled by the DBMS
USERS & PROCESSES
©P00482 - 2008 10
DBMS
• Data Definition Language
to create and modify database objects
• Query Language
to support all forms of retrieval and updating
• Interfaces to
operating system
telecommunication system
programming languages
other utility software
• Data Dictionary
- a complete description of the database structure and conten
©P00482 - 2008 11
VIEW C
VIEW B
VIEW A
CONCEPTUAL EXTERNAL
mapping
D
B
M
S CONCEPTUAL MODEL
CONCEPTUAL INTERNAL
mapping
INTERNAL MODEL
©P00482 - 2008 12
Database models
• Inverted files
• Hierarchical
• Network (CODASYL)
• Relational
• Deductive (logical)
• Object Oriented
• Functional
©P00482 - 2008 13
Relational database model
©P00482 - 2008 14
Modelling the data
©P00482 - 2008 15
entity
©P00482 - 2008 16
Property - a named characteristic of an entity
Attributes
properties that represent an entity in the target system
(i.e. those whose values are to be stored in the database)
Domain
a set of all permitted values for each attribute
©P00482 - 2008 17
LECTURER
CREDIT
TITLE VALUE
type
No COURSE TERM
Dr Brown
Database 2 units
Design
occurrence
©P00482 - 2008 18
No
TITLE
LECTURER COURSE entity-name
CREDIT
TERM
attribute-names
©P00482 - 2008 19
super-entity
common attributes
UNIVERSITY_MEMBER
ID, Name, DoB, PermAddress
STUDENT
sub-entity TermAddress, Fields
differentiating
attributes
LECTURER
Qualifications, Salary
©P00482 - 2008 20
A relationship is a named directed mapping between two entity types
• one-to-one
an element from one class is mapped to
exactly one element in another class
• one-to-many
an element from one class is mapped to
one or more elements in another class
• many-to-many
zero, one or more elements from one class are mapped to
zero, one or more elements in another class, and vice-versa
©P00482 - 2008 21
physical entities abstract entities
St-No
NAME
HomeADDRESS DEPT#
STUDENT DEPARTMENT NAME
TermADDRESS
SEX HEAD-Id
DOB
Staff-Id
MOD#
NAME TITLE
ADDRESS MODULE
LECTURER LECTURER
QUAL CREDIT
SALARY TERM
DOB
St-No
BUILDING TITLE
OFFICE# OFFICE PROJECT SUPERVISOR
AREA GRADE
YEAR
St-No
association MOD#
entity RESULTS
DATE
GRADE
©P00482 - 2008 22
COMPILER
John
DATABASE
Eve
EXPERT SYSTEM
Mary
WORDPROCESSOR
Steve
SPREADSHEET
www-BROWSER Ann
PROJECT is-carried
STUDENT
-out-by
optional compulsory
©P00482 - 2008 23
John
Smith Eve
Brown
Mary
Green Steve
Ann
optional compulsory
©P00482 - 2008 24
Introduction to Calculus
Mathematical Logic
John
Set Theory & Topology
Theory of Computation
Mary
Programming
Steve
Information Systems
Database Design
Artificial Intelligence
©P00482 - 2008 25
compulsory optional
m:n decomposition
STUDENT MODULE
RESULTS
©P00482 - 2008 26
super/sub entity
UNIVERSITY
MEMBER
carries_out
STUDENT
SYSTEM PROJECT
LECTURER
has_account_on
supervises
©P00482 - 2008 27
EAR DIAGRAM
DEPARTMENT delivers
prerequisite_for
employs
MODULE
occupied
OFFICE LECTURER
by is_on
has
supervises TEACHING
counsels SCHEME
carried
PROJECT STUDENT
out_by
enjoys
RESULTS
©P00482 - 2008 28
TRANSACTION PROPAGATION - SIMPLIFIED SCHEME
TEACHING
update teaching scheme ::=
SCHEME for all subjects taught by X
assign replacement lecturer;
PROJECT STUDENT if no suitable replacement
©P00482 - 2008 29
RELATIONAL MODEL PRINCIPLES
©P00482 - 2008 30
RELATIONAL MODEL as a FORMAL SYSTEM
STRUCTURE BEHAVIOUR
OPERATIONS
©P00482 - 2008 31
Sets
1 N
element set
a alphabet
membership test • DAYS = {Mon, Tue, Wed, Thu, Fri, Sat, Sun}
Mon DAYS,
BoxingDay DAYS
©P00482 - 2008 32
empty set
• contains no elements
{ }
• is a subset of every set
• no duplicates
{a, a, a, b, c, c} {a, b, c}
global rules
• order of elements immaterial
{John, Mary, Anne} {Anne, John, Mary}
©P00482 - 2008 33
Operations
inclusion B A
A B (x A x B) forall x A
union A B
A B (x: x A or x B)
difference A B
A \ B (x: x A and x B)
A B
intersection A B (x: x A and x B)
©P00482 - 2008 34
cartesian product
A
B
A x B
©P00482 - 2008 35
M
W
PETER
PAUL MARY
STEVE EVE
JAMES ANNE
GEORGE JANE
KEITH SUE
M x W =
{<PETER, MARY>, <PETER, EVE>, <PETER, ANNE>, <PETER, JANE>, <PETER, SUE>,
<PAUL, MARY>, <PAUL, EVE>, <PAUL, ANNE>, <PAUL, JANE>, <PAUL, SUE>,
<STEVE, MARY>, <STEVE, EVE>, <STEVE, ANNE>, <STEVE, JANE>, <STEVE, SUE>,
<JAMES, MARY>, <JAMES, EVE>, <JAMES, ANNE>, <JAMES, JANE>, <JAMES, SUE>,
<GEORGE, MARY>, <GEORGE, EVE>, <GEORGE, ANNE>, <GEORGE, JANE>, < GEORGE, SUE>,
<KEITH, MARY>, < KEITH, EVE>, < KEITH, ANNE>, < KEITH, JANE>, < KEITH, SUE>}
©P00482 - 2008 36
M
W
PETER
PAUL MARY
STEVE EVE
JAMES ANNE
GEORGE JANE
KEITH SUE
M x W =
{<PETER, MARY>, <PETER, EVE>, <PETER, ANNE>, <PETER, JANE>, <PETER, SUE>,
<PAUL, MARY>, <PAUL, EVE>, <PAUL, ANNE>, <PAUL, JANE>, <PAUL, SUE>,
<STEVE, MARY>, <STEVE, EVE>, <STEVE, ANNE>, <STEVE, JANE>, <STEVE, SUE>,
<JAMES, MARY>, <JAMES, EVE>, <JAMES, ANNE>, <JAMES, JANE>, <JAMES, SUE>,
<GEORGE, MARY>, <GEORGE, EVE>, <GEORGE, ANNE>, <GEORGE, JANE>, < GEORGE, SUE>,
<KEITH, MARY>, < KEITH, EVE>, < KEITH, ANNE>, < KEITH, JANE>, < KEITH, SUE>}
©P00482 - 2008 37
MARRIAGE M x W =
RELATION ::=
a subset of cartesian product
where
for every pair (x, y) a pre-defined proposition p(x, y) holds true
attribute name
©P00482 - 2008 38
PERSON-NAMES BIRTH-DATES
CITIES A relation R is a subset
of an
Smith
London
expanded cartesian product
Jones
of n, not necessarily
02-01-1950
distinct
Brown
Paris
03-01-1950
Green
.
30-12-1999
.
attribute
a predefined proposition
(role) name
2,...,n
Smith 02-11-1950 London
tuple (row)
Jones 22-03-1955 New York
relation
Brown 30-09-1972 Paris
k is a number of tuples in
name
column
©P00482 - 2008
value
n is a number of attributes
39
R l R’
©P00482 - 2008 40
domains is said to be a superkey
for R if and only if
p(dk) and p'(l) are
referentially equivalent,
i.e.
whenever p(dk) and p'(l)
If m is minimal then
is a proper candidate
©P00482 - 2008 key for R 41
REGISTER REGISTER’
©P00482 - 2008 42
First Normal Form
STUDENT-RECORD
ST-REC
RECORD
Programming A
Databases B
Data Structures C
©P00482 - 2008 43
…or a list
MODULES-TAKEN
MODULES
ID
M1 M2 M3
S011 Mathematics Programming Databases Data Structures
S173 Electronics Prolog Mathematics
S112 Programming Prolog nil
MOD-TAKEN
ID MODULE
S011 Mathematics
S011 Programming
First Normal Form S011 Databases
S011 Data Structures
S173 Electronics
S173 Prolog
S173 Mathematics
S112 Programming
S112 Prolog
©P00482 - 2008 44
Entity Integrity
DIRECTORY
FNAME SNAME ADDRESS TELEPHONE
John Adams 1 High Str 01234 123456
Mary Adams 11 North Av 01234 234567
x Adams 9 South Av 01234 345678
Peter x 5 Dore Clo 01234 456789
x x 13 Back Str 01234 567890
©P00482 - 2008 45
Referential Integrity If a relation R includes a foreign key match
the primary key of some other relation M, th
every value of in R must be equal to the val
of in some tuple of R or br wholly null
REGISTER
S-ID SUBJECT GRADE
s011 Mathematics B
s011 Programming A
MODULE
s011 Databases B
SUBJECT LECTURER-ID
s011 Data Structures C
not allowed s011 Mathematics p123
Psychology A
Programming p234
s173 Computer Arch A
Data Structures p345
s173 Artificial Intell B
Databases p345
s173 Mathematics A
Computer Arch p123
s112 Programming C
Artificial Intell p567
s112 Artificial Intell A
primary key
foreign key
REGISTER.SUBJECT
MODULE.SUBJECT
©P00482 - 2008 46
RELATIONAL MODEL SUMMARY
©P00482 - 2008 47
occupied_by
OFFICE LECTURER
X
N101 New Block
©P00482 - 2008 49
LECTURER counsels STUDENT
©P00482 - 2008 50
foreign
key
LECTURER decomposed MODULE
TEACHING
SCHEME
8050 MM 8012
foreign
foreign
key key
ID CODE …..
S027 8049
S229 8012
©P00482 - 2008 51
S341 8011 …..
MODULE
MODULE
CODE PREQ
........ ........
8003 8001
8002 8008
8008 8003
8011 8008
8010 8002
8025
8025 8011
8025 8012
8025
8025 8010
8029 8025
8027 8029
8027 8025 8047
........ ........
CODE PREQ
©P00482 - 2008 8047 8025
8025 new record 52
UNIVERSITY
MEMBER
UNIVERSITY
ID NAME DOB ADDRESS
MEMBER
super-entity
STUDENT
…….. …………. …….. ………….
LECTURER
exc_or
sub-entities
STUDENT LECTURER
ID HALL ENROL-DATE ID QUALIFIC SALARY
©P00482 - 2008 53
Referential Integrity Diagram
STUDENT
STNO NAME SEX DOB ADDRESS ENTRY
REGISTER
STNO CODE RESULT WHEN
MODULE
CODE TITLE REQUIRES TEACHID
LECTURER
ID NAME DOB ADDRESS QUALIF POSITION
OFFICE
ID NUMBER BUILDING
©P00482 - 2008 54