Review
Review
Database Approach
Basic Terminology
Data:
Database: A collection of data that describes the activities of one or more
related organizations.
DBMS: A software designed to manage the creation, manipulation and access
to the database.
File Systems
o Data stored as computer files
o Data processing specialist needed to:
- Create necessary computer file structures
- Write software that managed data with those structures
- Design application programs that produced reports based
on the file data
File Systems
Limitations of file-based systems
Separation and isolation of data
Duplication of data
Data dependence
Incompatible file formats
Fixed queries/proliferation of application programs
Database Approach
Advantages of DBMS over file based systems.
External Schema
Correspond to different views of the data
Conceptual Schema
Describes all the entities, attributes, and
relationships together with integrity
constraints
Internal Schema
Complete description of the internal
model (data fields, the indexes and
storage structures used)
There is only one conceptual schema and one internal schema per database.
Architecture
Multi-user Architecture
Produce a list of salaries for all staff, showing only the staffNo, fName, lName, and salary
details.
Produce the staffno and first names of all staff earning a salary greater than 10,000
List the names and comments of all clients who have viewed a property for rent.
List the names and comments of all clients who have viewed a property for rent.
Natural Join:
Enforces equality on all attributes with the same name
Eliminates one copy of duplicate attributes
Relational Algebra
Theta Join ( ) )
Picks columns from more than one table
Theta Join containing only equality, the term Equijoin is used instead.
Relational Algebra
Relationships
Multiplicity
A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples
uniquely identified by P and C’s keys
Multiplicity of Relationships
1 a
One-to-one: 2
3
b
c
d
1 a
Many-to-one: 2
3
b
c
d
1 a
b
One-to-many: 2
3 c
d
1 a
Many-to-many: 2
3
b
c
d
Multiplicity of Relationships
Each object of class c1 is related to at least m and at most n objects of c2
m…n A m…n
CC1 CC2
Constraints
• Entity Integrity Constraint
In a base relation, no attribute of a primary key can be null (null means unknown)
• Keys: Implicit constraints on uniqueness of entities
• Ex: An SSN uniquely identifies a person
• Single-value constraints:
• Ex: a person can have only one father
• Other constraints:
• Ex: peoples’ ages are between 0 and 150
Normalization
What you Learnt
Redundancy and data anomalies
Functional Dependencies
Normalization Process
Anomalies in data
A poorly designed database causes anomalies
If we update the
room number for
one tuple, we get
inconsistent data
If everyone drops the class, we lose what room the class is in! = a = an update
delete anomaly anomaly
Functional dependencies
Functional dependencies describes the relationships between attributes.
A B C
a1 b1 c1
a1 b1 c2
{name} {color}
F= {category} {department}
{color, category} {price}
Atomic
Consistent
Transaction moves from a state where integrity holds, to another where integrity holds
Isolated
Effect of transactions is the same as transactions running one after another (ie looks like
batch mode)
Durable
159 106
Interleaved schedule A
Same Result
159 106
Scheduling transactions
Comparing results of serial and non-serial schedule Starting Account Balances
Consider previous examples of transaction 1 and transaction 2 A B
159 106
Interleaved schedule B
Different Result!!
159 112
Anomalies with interleaved execution
They include:
Unrepeatable read
Dirty Read/ Reading Uncommitted data
Lost update problem
Inconsistent analysis problem
Concurrency Control Techniques
Two phase Locking
Timestamping
Lock Granularity