0% found this document useful (0 votes)
5 views

Chapter 2

Chapter 2 introduces the relational model, defining relation schemas, instances, and the concept of attributes and their domains. It explains the significance of keys, including superkeys and candidate keys, in uniquely identifying tuples within relations, and discusses foreign key constraints. The chapter emphasizes the importance of proper database design to avoid redundancy and null values, leading to better normalization practices.

Uploaded by

yeshwanth vemula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Chapter 2

Chapter 2 introduces the relational model, defining relation schemas, instances, and the concept of attributes and their domains. It explains the significance of keys, including superkeys and candidate keys, in uniquely identifying tuples within relations, and discusses foreign key constraints. The chapter emphasizes the importance of proper database design to avoid redundancy and null values, leading to better normalization practices.

Uploaded by

yeshwanth vemula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 2: Intro to

Relational Model

Modifies from: Database System


Concepts ©Silberschatz, Korth and
Sudarshan
See www.db-book.com for conditions on
re-use
Relation Schema and Instance
A1, A2, …, An are attributes names
R = (A1, A2, …, An ) is a relation schema
Example: instructor = (ID, name, dept_name, salary)
Formally, given sets D1, D2, …. Dn of domains a
relation r (or relation instance) is a subset of
D1 x D2 x … x Dn
Thus, a relation is a set of n-tuples (a1, a2, …, an)
where each ai ∈ Di

A1 A2 An
tuple a1 a2 an
Example of a Relation
The current values (relation instance) of a relation are often specified in
tabular form
Caveat: being a set, the tuples of the relation do not have any order
defined as implied by the tabular representation
An element t of r is a tuple, represented as a row in a table
attributes
(or columns)

Tuples ordered by ID
(or rows)
Attribute Types
The set of allowed values for each attribute is called
the domain or data type of the attribute
Attribute values are (normally) required to be atomic;
that is, indivisible
E.g., integer values
E.g., not address (street, city, zip code, state, country)

The special value null is a member of every domain


Means unknown or not applicable
Alternative Definitions
A relation schema is often defined as a list of
attribute-domain pairs
That is the data types of each attribute in the relation are
considered as part of the relation schema
Tuples are sometimes defined as functions from
attribute names to values (order of attributes does
not matter)
E.g., t(name) = ‘Bob’
A relation r can be specified as a function
D1 x D2 x … x Dn -> {true, false}
t = (a1, a2, …, an) is mapped to true if t is in r and to false
otherwise
These alternative definition are useful in database
theory
◦ We will stick to the simple definition!
Relations are Unordered
Order of tuples is irrelevant (tuples may be stored in an arbitrary
order)
Example: instructor relation with unordered tuples
Database
A database schema S consists of multiple relation schema
A database instance I for a schema S is a set of relation instances
One relation for each relation schema in S
Information about an enterprise is broken up into parts
instructor
student
advisor
Bad design:
univ (instructor -ID, name, dept_name, salary, student_Id, ..)
results in
repetition of information (e.g., two students have the same instructor)
the need for many null values (e.g., represent an student with no advisor)
Normalization theory (Chapter 7) deals with how to design “good”
relational schemas avoiding these problems
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)
Example: {ID} and {ID,name} are both superkeys of
instructor.
Superkey K is a candidate key if K is minimal (no
subset of K is also a superkey)
Example: {ID} is a candidate key for Instructor
One of the candidate keys is selected to be the
primary key.
which one? -> domain specific design choice
Keys
Foreign key constraint: Value in one relation must appear in
another
Referencing relation of a foreign key
Referenced relation
Keys
Formally, a set of attributes K ⊆ R is a superkey if for
every instance r of R holds that
∀t, t’ ∊ r: t.K = t’.K ⇒ t = t’
A superkey K is called a candidate key iff
∀K’ ⊆ K: K’ is not a superkey
A foreign key constraint FK is quartuple (R, K, R’, K’)
where R and R’ are relation schemata, K ⊆ R, K’ is
the primary key of R’, and |K| = |K’|
A foreign key holds over an instance {r, r’} for {R,R’} iff
∀t ∊ R:∃t’ ∊ R’: t.K = t’.K’
Schema Diagram for the University Database

You might also like