Database Fundamentals: Robert J. Robbins Johns Hopkins University
Database Fundamentals: Robert J. Robbins Johns Hopkins University
Fundamentals
Robert J. Robbins
Johns Hopkins University
rrobbins@gdb.org
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 1
What is a Database?
General:
A database is any collection of related data.
Restrictive:
A database is a persistent, logically coherent
collection of inherently meaningful data, relevant
to some aspects of the real world.
The portion of the real world relevant to the database is sometimes referred
to as the universe of discourse or as the database miniworld. Whatever it
is called, it must be well understood by the designers of the database.
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 2
External Level
(individual user views)
Conceptual Level
(Enterprise-wide view\)
Internal Level
(storage view)
Storage Level
(physical storage)
File: N_drive:\jhu\class\1995\db-fund.ppt
External
View 1
External
View n
Conceptual
Schema
Internal
Schema
Physical
Database
1994, 1995 Robert Robbins
Database Fundamentals: 3
allow concurrency
control security
control redundancy
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 4
systems analysts
database designers
database administrators
application developers
users
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 5
Direct User
Queries
Application
Programs
Database
Administrator
DML
Processor
DDL
Compiler
Authorization
Tables
Database
Manager
Database
Description
Tables
Concurrent
Access
Tables
File
Manager
System
Catalog
File: N_drive:\jhu\class\1995\db-fund.ppt
Physical
System
Database
1994, 1995 Robert Robbins
Metadata
Database
Database Fundamentals: 6
What is a relation?
a kind of set
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 7
CARTESIAN
PRODUCT
example
Note:
RELATION
example
Note:
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 8
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 9
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 10
LET
THEN
File: N_drive:\jhu\class\1995\db-fund.ppt
<1,1>
<1,2>
<1,3>
<1,4>
<1,5>
<1,6>
<3,1>
<3,2>
<3,3>
<3,4>
<3,5>
<3,6>
<5,1>
<5,2>
<5,3>
<5,4>
<5,5>
<5,6>
<2,1>
<2,2>
<2,3>
<2,4>
<2,5>
<2,6>
<4,1>
<4,2>
<4,3>
<4,4>
<4,5>
<4,6>
<6,1>
<6,2>
<6,3>
<6,4>
<6,5>
<6,6> }
Database Fundamentals: 11
Set B
<1,1>
<1,2>
<1,3>
<1,4>
<1,5>
<1,6>
<3,1>
<3,2>
<3,3>
<3,4>
<3,5>
<3,6>
<5,1>
<5,2>
<5,3>
<5,4>
<5,5>
<5,6>
<2,1>
<2,2>
<2,3>
<2,4>
<2,5>
<2,6>
<4,1>
<4,2>
<4,3>
<4,4>
<4,5>
<4,6>
<6,1>
<6,2>
<6,3>
<6,4>
<6,5>
<6,6>
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 12
<2,1>
<2,2>
<2,3>
<2,4>
<2,5>
<2,6>
<3,1>
<3,2>
<3,3>
<3,4>
<3,5>
<3,6>
<1,1>
<2,2>
<3,3>
<4,4>
<4,1>
<4,2>
<4,3>
<4,4>
<4,5>
<4,6>
<5,1>
<5,2>
<5,3>
<5,4>
<5,5>
<5,6>
<6,1>
<6,2>
<6,3>
<6,4>
<6,5>
<6,6>
File: N_drive:\jhu\class\1995\db-fund.ppt
<5,5>
<6,6>
Database Fundamentals: 13
S1
S2
S1 x
S2
S3
Sn
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 14
Relations as a Database
An n-ary relation (i.e., a subset of a Cartesian product of n sets) could be be
represented in a computer system as an n-column tabular file, with one member
from the first set named in the first column of each record and one member of
the second set in the second column, etc.
S1 x
S2
S3
Sn
Smith
Robert
L.
Glendale
MD
21200
Smith
Judy
F.
Glendale
MD
21200
Jones
Greg
G.
Towson
MD
21232
Harris
Lloyd
K.
2323 Maple Dr
Towson
MD
21232
Ziegler
Fred
File: N_drive:\jhu\class\1995\db-fund.ppt
K.
Baltimore
MD
21208
Database Fundamentals: 15
Relations as a Database
The business data file resembles a relation in a number of ways. The tabular
file itself corresponds to a relation. Each column, or attribute, in the file
corresponds to a particular set and all of the values from a particular column
come from the same domain, or set. Each row, or record, in the file
corresponds to a tuple
Domains
(sets)
Name-L
Name-F
MI
address
city
state
zip
Smith
Robert
L.
Glendale
MD
21200
Smith
Judy
F.
Glendale
MD
21200
Jones
Greg
G.
Towson
MD
21232
Harris
Lloyd
K.
2323 Maple Dr
Towson
MD
21232
Ziegler
Fred
K.
Baltimore
MD
21208
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 16
Relations as a Database
An essential attribute of a relation is that every tuple must be unique. This
means that the values present in some individual attribute (or set of attributes)
must always provide enough information to allow a unique identification of
every tuple in the relation. In a relational database, these identifying values
are known as key values or just as the key.
Sometimes more than one key could be defined for given table. For
example, in the table below (which represents, perhaps, a patient record file),
several columns might serve as a key. Either patient number (assigned by
the hospital) or social security number (brought with the patient) are
possibilities. In addition, one might argue that the combination of last name,
address, and birth date could collectively serve as a key.
Any attribute or set of attributes that might possibly serve as a key is known
as a candidate key. Keys that involve only one attribute are known as
simple keys. Keys that involve more than one attribute are composite keys.
patient #
SS #
Last Name
address
birth date
P-64122
123-45-6789
Smith
10 MAY 44
P-75642
001-32-6873
Pedersen
31 MAR 59
P-70875
444-44-5555
Wilson
7 AUG 90
P-79543
555-12-1212
Grant
1 DEC 66
P-71536
888-88-8888
MacPherson
11 APR 60
In designing a database, one of the candidate keys for each relation must be
chosen to be the primary key for that table. Choosing primary keys is a
crucial task in database design. If keys need to be redesignated, the entire
system may have to be redone. Primary keys can never be null and should
never be changed. Sometimes none of the candidate keys for a relation are
likely to remain stable over time. Then, an arbitrary identifier might be created
to serve as a primary key. Such arbitrary keys are also known as surrogate
keys.
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 17
Relations as a Database
A binary relation (i.e., a subset of a Cartesian product of two sets) could be be
represented in a computer system as two-column tabular file, with one member
from the first set named in the first column of each record and one member of
the second set in the second column. For example, a binary relation could be
used to provide unique three-letter identifiers for academic departments.
Additional relations could be used to give more information about individual
departments or individual faculty members.
ZOL
Zoology
PSD
Political Science
CPS
Computer Science
HIS
History
ACC
Accounting
ZOL
Zoology
Room 203
355 4640
CPS
Computer Science
Room 714A
Wells Hall
355 5210
BSP
Biological Science
Room 141
353 4610
CEM
Chemistry
Room 320
Chemistry Bldg
355 9175
PSD
Room 303
Political Science
355 6590
999-99-9999
Johnson
William
F.
Baltimore
MD
21211
888-88-8888
Johnson
William
F.
Baltimore
MD
21201
777-77-7777
Brown
James
G.
99 W. East St.
Towson
MD
21232
666-66-6666
Brown
Gwen
K.
99 W. East St.
Towson
MD
21232
111-11-1111
Ziegler
File: N_drive:\jhu\class\1995\db-fund.ppt
Samual
L.
Baltimore
MD
21208
Database Fundamentals: 18
Relations as a Database
Yet another relation could be used to show what faculty were members of what
departments. Notice that faculty member 999-99-9999 is a member of more
than one department and that, even on this short list, the department of zoology
has two members given.
999-99-9999
ZOL
888-88-8888
PSD
7777-77-7777
CPS
666-66-6666
ZOL
999-99-9999
BSP
Relations of this sort, that combine identifiers from two other relations, provide
the glue that holds a relational database together.
other fields
Member-of Relation
SS Number
SS Number
Departments Relation
Faculty Relation
Dept Code
Dept Code
other fields
Whenever the values in an attribute column in one table point to primary keys
in another (or the same) table, the attribute column is said to be a foreign key.
Columns containing foreign keys are subject to an integrity constraint: any
value present as a foreign key must also be present as a primary key.
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 19
Cartesian product
union
intersection
difference
select
project
join
divide
outer join
outer union
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 20
Database Fundamentals: 21
other fields
Member-of Relation
SS Number
SS Number
Departments Relation
Faculty Relation
Dept Code
Dept Code
other fields
The three files represented above are all relations in the formal sense. Chen
(1976) noted that different relations may play different roles in a database and
that being able to recognize and document those roles is a key part of database
design. The faculty and the department relations above both store
information about particular real-world entities. The member-of relation, on
the other hand, stores information about specific relationships involving
individual pairs of real-world entities.
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 22
External
View n
Conceptual
Database
Physical
Database
Implemented on physical
devices, using a commercial
database product
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 23
Conceptual
Database
(E-R)
Conceptual
Database
(relational)
Physical
Database
File: N_drive:\jhu\class\1995\db-fund.ppt
External
View n
The
entity-relationship
approach (Chen, 1976)
improved the mapping
between the semantics of a
database design and that
portion of the real world
being modeled with the
data.
Database Fundamentals: 24
External
View 1
Conceptual
Database
(E-R)
Conceptual
Database
(relational)
If a commercial RDBMS is
used, a relational conceptual
model provides a basis for
designing and implementing
an underlying physical
database.
File: N_drive:\jhu\class\1995\db-fund.ppt
External
View n
If a commercial relational
database system is used,
mapping from a relational
conceptual model to the
physical database should be
relatively straightforward.
Physical
Database
Database Fundamentals: 25
Faculty
Departments
Students
Classrooms
Courses
Departments
4,n
majors
in
1,2
Students
Arcs are drawn with an orientation that points from foreign keys to primary
keys. The min:max participation cardinality can be indicated by placing
pairs of numbers on each arc. Here, 4,n means that every department is
required to have at least four student majors, but can have many more; 1,2
means that each student is required to have at least one major and is permitted
to have no more than two majors. Sometimes only the maximum participation
cardinalities are shown.
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 26
Many-to-one:
Entity Set A
Relates
Relates
Entity Set B
Entity Set B
One-to-many:
Entity Set A
Entity Set B
Relates
Entity Set B
Relates
1:n
Entity Set B
Relates
0:n
Entity Set B
Relates
Many-to-many:
Entity Set A
One-to-many:
(mandatory)
Entity Set A
One-to-many:
(optional)
Entity Set A
File: N_drive:\jhu\class\1995\db-fund.ppt
1:1
1:1
Database Fundamentals: 27
Departments
member
of
Faculty
Departments
1,1
chairman
of
0,1
Faculty
The 1,1 cardinality for departments means that every department must have
one and only one chairman. The 0,1 cardinality for faculty means that not all
faculty participate in the chairman-of relationship and that no faculty member
may participate more than once. That is, not all faculty are chairmen and no one
faculty member may serve as chairman of more than one department.
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 28
Departments
member
of
1,1
chairman
of
0,1
Faculty
member
of
Faculty
0,1
1,1
File: N_drive:\jhu\class\1995\db-fund.ppt
chairman
of
Database Fundamentals: 29
Person
1:n
ISA
1:n
1:n
1:n
Faculty
1:n
Staff
Student
1:n
1:n
ISA
ISA
1:n
1:n
Tenured
1:n
Untenured
File: N_drive:\jhu\class\1995\db-fund.ppt
1:n
1:n
1:n
Temporary
Graduate
1:n
Undergraduate
1:n
Nondegree
Database Fundamentals: 30
mother:child
This cardinality indicates that
not all persons participate in the
relationship as mothers, but that
those who do participate may
participate one or more times.
0:n
1:1
All Persons
File: N_drive:\jhu\class\1995\db-fund.ppt
Database Fundamentals: 31