Database - 02 - Relational Model
Database - 02 - Relational Model
Relational Model
Introduction
The relational model is today the primary data model for
commercial data processing applications. It attained its primary
position because of its simplicity, which eases the job of the
programmer, compared to earlier data models such as the
network model or the hierarchical model.
Relational Model 2
Structure of Relational Databases
A relational database consists of a collection of tables, each of
which is assigned a unique name.
Relational Model 3
Structure of Relational Databases
Relational Model 4
Structure of Relational Databases
In the relational model,
• the term relation is used to refer to a table,
• the term tuple is used to refer to a row,
• the term attribute refers to a column of a table.
Relational Model 5
Structure of Relational Databases
For each attribute of a relation, there is a set of permitted values,
called the domain of that attribute. Thus, the domain of the
salary attribute of the instructor relation is the set of all possible
salary values, while the domain of the name attribute is the set of
all possible instructor names.
Relational Model 6
Structure of Relational Databases
• We require that, for all relations r, the domains of all attributes
of r be atomic.
Relational Model 7
Structure of Relational Databases
The important issue is not what the domain itself is, but rather
how we use domain elements in our database. Suppose now
that the phone number attribute stores a single phone number.
Even then, if we split the value from the phone number attribute
into a country code, an area code and a local number, we would
be treating it as a non-atomic value. If we treat each phone
number as a single indivisible unit, then the attribute phone
number would have an atomic domain.
The null value is a special value that signifies that the value is
unknown or does not exist. null values cause a number of
difficulties when we access or update the database, and thus
should be eliminated if at all possible.
Relational Model 8
Database Schema
Database schema: the logical design of the database
database instance: a snapshot of the data in the database at a
given instant in time.
In general, a relation schema consists of a list of attributes and
their corresponding domains.
(We shall not be concerned about the precise definition of the domain of
each attribute until we discuss the SQL language in Chapter 3.)
Relational Model 9
Database Schema
The concept of a relation corresponds to the programming-
language notion of a variable, while the concept of a relation
schema corresponds to the programming-language notion of type
definition. The concept of a relation instance corresponds to the
programming-language notion of a value of a variable. The value
of a given variable may change with time; similarly the contents
of a relation instance may change with time as the relation is
updated. In contrast, the schema of a relation does not generally
change.
Relational Model 10
Database Schema
Consider the department relation of Figure 2.5.
Relational Model 11
Database Schema
Note that the attribute dept name appears in both the instructor
schema and the department schema. This duplication is not a
coincidence. Rather, using common attributes in relation
schemas is one way of relating tuples of distinct relations.
Relational Model 12
Database Schema
Each course in a university may be offered multiple times, across
different semesters, or even within a semester. We need a
relation to describe each individual offering, or section, of the
class. The schema is
section (course_id, sec_id, semester, year, building,
room_number, time_slot_id)
Relational Model 13
Database Schema
Relational Model 14
Database Schema
We need a relation to describe the association between
instructors and the class sections that they teach. The relation
schema to describe this association is
teaches (ID, course_id, sec_id, semester, year)
Relational Model 15
Database Schema
Relational Model 16
Database Schema
As you can imagine, there are many more relations maintained in
a real university database. In addition to those relations we have
listed already, instructor, department, course, section, prereq, and
teaches, we will be using the following relations in our class:
Relational Model 17
Keys
We must have a way to specify how tuples within a given relation
are distinguished. This is expressed in terms of their attributes.
That is, the values of the attribute values of a tuple must be such
that they can uniquely identify the tuple.
Relational Model 18
Keys
A superkey of a relation is a set of one or more attributes whose
values are guaranteed to identify tuples in the relation uniquely.
Relational Model 19
Schema Diagrams
database schema, along with primary key and foreign key
dependencies, can be depicted by schema diagrams. Figure 2.8
shows the schema diagram for our university organization. Each
relation appears as a box, with the relation name at the top in
blue, and the attributes listed inside the box. Primary key
attributes are shown underlined. Foreign key dependencies
appear as arrows from the foreign key attributes of the
referencing relation to the primary key of the referenced relation.
Relational Model 20
Schema Diagrams
Relational Model 21
Schema Diagrams
The enterprise that we use in the examples in later chapters is a
university. Figure 2.9 gives the relational schema that we use in
our examples, with primary key attributes underlined.
Relational Model 22
Relational Operations
The relational query languages define a set of operations that
operate on tables, and output tables as their results. These
operations can be combined to get expressions that express
desired queries.
Relational Model 23
Relational Operations
Relational Model 24
Relational Operations
Relational Model 25
Relational Operations
Relational Model 26
Relational Operations
Relational Model 27
Relational Operations
Relational Model 28
Relational Operations
Relational Model 29
Relational Operations
Relational Model 30
Relational Operations
Relational Model 31
Relational Operations
Relational Model 32
Related Resources
➢ https://www.tutorialspoint.com/dbms/index.htm
Relational Model 33