Lec2 Relational Model 1b3
Lec2 Relational Model 1b3
(web browser)
Old Modern
Database Management System Internals
Storage management
Query processing
Transaction processing
Storage Management
Storage manager is a program module that provides the interface
between the low-level data stored in the database and the application
programs and queries submitted to the system.
The storage manager is responsible for:
Interaction with the file manager
Efficient storing, retrieving and updating of data
Issues:
Storage Access
File organization
Indexing and hashing
Query Processing
D1 x D2 x … x Dn
Thus, a relation is a set of n-tuples (a1, a2, …, an) where each ai Di
Schema of a relation consists of
attribute definitions
name
type/domain STUDENT(Name: string, Ssn:
integrity constraints string, Home_phone: string,
Address: string, Office_phone:
string, Age: integer, Gpa:
real)
Relation Instance: Unordered
The current values (relation instance) of a relation are specified by a
table
An element t of r is a tuple, represented by a row in a table
Order of tuples is irrelevant (tuples may be stored in an arbitrary order)
attributes
(or columns)
customer_name customer_street customer_city
customer
Database
A database consists of multiple relations
Information about an enterprise is broken up into parts, with each
relation storing one part of the information
E.g.
The depositor
Relation
Why Split Information Across Relations?
Storing all information as a single relation such as
bank(account_number, balance, customer_name, ..)
results in
repetition of information
e.g.,if two customers own an account (What gets
repeated?)
the need for null values
e.g., to represent a customer without an account
Normalization theory deals with how to design relational
schemas
Keys
Let K R
K is a superkey of R if values for K are sufficient to identify a unique tuple of
each possible relation r(R)
by “possible r ” we mean a relation r that could exist in the enterprise
we are modeling.
Example: {customer_name, customer_street} and
{customer_name}
are both superkeys of Customer, if no two customers can possibly have
the same name
In real life, an attribute such as customer_id would be used instead of
customer_name to uniquely identify customers, but we omit it to keep
our examples small, and instead assume customer names are unique.
Keys (Cont.)
K is a candidate key if K is minimal
Example: {customer_name} is a candidate key for Customer, since it
is a superkey and no subset of it is a superkey.
Primary key: a candidate key chosen as the principal means of
identifying tuples within a relation
Should choose an attribute whose value never, or very rarely,
changes.
E.g. email address is unique, but may change
Foreign Keys
A relation schema may have an attribute that corresponds to the primary
key of another relation. The attribute is called a foreign key.
E.g. customer_name and account_number attributes of depositor are
foreign keys to customer and account respectively.
Only values occurring in the primary key attribute of the referenced
relation may occur in the foreign key attribute of the referencing
relation.
Schema Diagram