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

Database - 02 - Relational Model

The relational model is today's primary data model for commercial data processing. It uses tables (relations) with rows (tuples) and columns (attributes). Each attribute has a domain of permitted values. A relational database consists of a collection of tables, each with a unique name. The schema defines the structure of each table. Keys such as primary and foreign keys are used to uniquely identify and relate tuples across tables. Relational operations allow querying and manipulating the data in tables.

Uploaded by

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

Database - 02 - Relational Model

The relational model is today's primary data model for commercial data processing. It uses tables (relations) with rows (tuples) and columns (attributes). Each attribute has a domain of permitted values. A relational database consists of a collection of tables, each with a unique name. The schema defines the structure of each table. Keys such as primary and foreign keys are used to uniquely identify and relate tuples across tables. Relational operations allow querying and manipulating the data in tables.

Uploaded by

Rasd sda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

DATABASE SYSTEM

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.

We use the term relation instance to refer to a specific instance


of a relation, i.e., containing a specific set of rows. The instance of
instructor shown in Figure 2.1 has 12 tuples, corresponding to 12
instructors.

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.

• A domain is atomic if elements of the domain are considered


to be indivisible units.

• For example, suppose the table instructor had an attribute


phone number, which can store a set of phone numbers
corresponding to the instructor. Then the domain of phone
number would not be atomic, since an element of the domain
is a set of phone numbers, and it has subparts, namely the
individual phone numbers in the set.

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.

The schema for that relation is


department (dept_name, building, budget)

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:

student (ID, name, dept_name, tot_cred)


advisor (s_id, i_id)
takes (ID, course_id, sec_id, semester, year, grade)
classroom (building, room_number, capacity)
time slot (time slot_id, day, start_time, end_time)

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.

In other words, no two tuples in a relation are allowed to have


exactly the same value for all attributes.

✓ Key is an attribute or collection of attributes that


uniquely identifies an entity among entity set.
• For example, the student_ID or roll_no of a student makes
him/her identifiable among students.

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.

A candidate key is a minimal superkey, that is, a set of attributes


that forms a superkey, but none of whose subsets is a superkey.

One of the candidate keys of a relation is chosen as its primary


key.

A foreign key is a set of attributes in a referencing relation, such


that for each tuple in the referencing relation, the values of the
foreign key attributes are guaranteed to occur as the primary key
value of a tuple in the referenced relation.

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.

The relational algebra provides a set of operations that take one


or more relations as input and return a relation as an output.
Practical query languages such as SQL are based on the relational
algebra, but add a number of useful syntactic features.

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

➢ Database System Concepts (6th Edition)


• Chapter 2

➢ https://www.tutorialspoint.com/dbms/index.htm

Relational Model 33

You might also like