0% found this document useful (0 votes)
46 views38 pages

Introduction To Relational Model

The document introduces key concepts of the relational database model including tables, tuples, attributes, domains, null values, schemas, relation instances, keys such as candidate keys, primary keys and foreign keys. It also describes common relational operations like selection, projection, join, union, difference and intersection. Relational query languages are discussed including relational algebra and calculus. Diagrams are provided to illustrate relational schema and operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views38 pages

Introduction To Relational Model

The document introduces key concepts of the relational database model including tables, tuples, attributes, domains, null values, schemas, relation instances, keys such as candidate keys, primary keys and foreign keys. It also describes common relational operations like selection, projection, join, union, difference and intersection. Relational query languages are discussed including relational algebra and calculus. Diagrams are provided to illustrate relational schema and operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 38

Chapter 2:

Introduction to Relational Model


Relational Model

• The relational data model is based on a collection of tables each of


which is assigned a unique name.
• The user of the database system may query these tables, insert new
tuples, delete tuples, and update (modify) tuples. There are several
languages for expressing these operations.
Example of a Relation
attributes
(or columns)

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)

• An instance of the relation refers to its contents at a point in time.


• The current values (relation instance) of a relation are specified by
the row a of a table.
• An element t of r is a tuple, represented by a row in a table.
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 consists of multiple relations
• 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 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.

Secondary or Alternative key


•The candidate key which are not selected for primary key are known as secondary
keys or alternative keys
Non-prime Attribute
•An attribute, which is not a part of the prime-key, is said to be a non-prime
attribute.
Schema Diagram for University Database
Relational Query Languages
• Procedural vs. non-procedural, or declarative
• Procedural: the user instructs the system to perform a sequence of
operations on the database to compute the desired result.
• Non-procedural: the user describes the desired information without
giving a specific procedure for obtaining that information.
• “Pure” and formal languages:
• Relational algebra
• Tuple relational calculus
• Domain relational calculus
• Relational operators
Selection of tuples
 Relation r

 Select tuples with A=B


and D > 5
σ A=B and D > 5 (r)
Selection of Columns (Attributes)
• Relation r:

 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:

•rs
Joining two relations – Natural Join

• Let r and s be relations on schemas R and S respectively.


Then, the “natural join” of relations R and S is a relation on schema
R  S obtained as follows:
• Consider each pair of tuples tr from r and ts from s.
• If tr and ts have the same value on each of the attributes in R  S,
add a tuple t to the result, where
• t has the same value as tr on r
• t has the same value as ts on s
Natural Join Example

• 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

You might also like