Introduction To Relational Model
Introduction To Relational Model
tuples
(or rows)
Relation:
A Table
Tuple:
A Row
Attributes:
A Column header
Attribute Types
the relational model the term relation is used to refer to a table,
while the term tuple is used to refer to a row. Similarly, the term
attribute refers to a column of a table.
•The set of allowed values for each attribute is called the domain of
the attribute
•Attribute values are (normally) required to be atomic; that is,
indivisible
•The special value null is a member of every domain
•The null value causes complications in the definition of many
operations
Relation Schema and Instance
• The schema of a relation refers to its logical design. The schema of a
relation includes its attributes, and optionally the types of the
attributes and constraints on the relation such as primary and foreign
key constraints.
• Example: instructor(id, name, dept_name, salary)
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 null values (e.g., represent an student with no advisor)
• Normalization theory (Chapter 7) deals with how to design “good”
relational schemas
Database Keys
Keys are very important part of Relational database. They are used to establish
and identify relation between tables. They also ensure that each record within a
table can be uniquely identified by combination of one or more fields within a
table.
• Super Key
• Candidate Key
• Primary Key
• Foreign Key
• Composite Key
• Secondary or Alternative key
• Non-prime Attribute
Super Key
Super Key
•A Super key is any combination of fields within a table that uniquely identifies
each record within that table.
Or
•Super Key is defined as a set of attributes within a table that uniquely identifies
each record within a table. Super Key is a superset of Candidate key.
Candidate Key
Candidate Key
•A candidate is a subset of a super key. A candidate key is a single field or the
least combination of fields that uniquely identifies each record in the table.
Or
•A Candidate Key can be any column or a combination of columns that can
qualify as unique key in database. There can be multiple Candidate Keys in
one table. Each Candidate Key can qualify as Primary Key
The least combination of fields distinguishes a candidate key from a super
key. Every table must have at least one candidate key but at the same time can
have several.
Primary Keys
Primary Keys
•The primary key consists of one or more columns whose data contained
within is used to uniquely identify each row in the table.
Or
•A primary key is a column (or columns) in a table that uniquely
identifies the rows in that table.
•When a primary key is composed of multiple columns, the data from each
column is used to determine whether a row is unique.
Foreign Key
Foreign Key
•A foreign key is generally a primary key from one table that appears as a field
in another where the first table has a relationship to the second.
•Or
•A foreign key is a set of one or more columns in a table that refers to the
primary key in another table.
In other words, if we had a table A with a primary key X that linked to a table B
where X was a field in B, then X would be a foreign key in B.
Comparison of Primary Keys to Foreign Keys
Composite Key
•Key that consist of two or more attributes that uniquely identify an entity
occurrence is called Composite key. But any attribute that makes up the
Composite key is not a simple key in its own.
Select A and C
Projection
Π A, C (r)
Joining two relations – Cartesian Product
Relations r, s:
r x s:
Union of two relations
• Relations r, s:
r s:
Set difference of two relations
• Relations r, s:
r – s:
Set Intersection of two relations
• Relation r, s:
•rs
Joining two relations – Natural Join
• Relations r, s:
Natural Join
r s
Figure in-2.1
End of Chapter 2
Figure 2.01
Figure 2.02
Figure 2.03
Figure 2.04
Figure 2.05
Figure 2.06
Figure 2.07
Figure 2.10
Figure 2.11
Figure 2.12
Figure 2.13