0% found this document useful (0 votes)
17 views25 pages

Unit III Relational Model 1

Uploaded by

bisol27639
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views25 pages

Unit III Relational Model 1

Uploaded by

bisol27639
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Unit III: Relational Model

Part-1

Dr. Anushree Tripathi


Department of Computer Science and Engineering
National Institute of Technology Patna (NITP)

17th September, 2024


Syllabus (Theory)
UNIT III: Relational Model

• Structure of relational databases


• Relational algebra
• Tuple relational calculus
• Domain relational calculus
• Extended relational-algebra operations
• Modification of the database and view
• SQL and Other
Overview
• Structure of relational databases
➢ Basic structure
➢ Database schema
➢ Keys
➢ Schema diagram
➢ Query Languages
Structure of relational databases
Introduction

Collection of relations

Relations: Table of values

Row: Real world entity/ relationship

Column names: Interpret meaning of values in each


row
Structure of relational databases
Introduction

Column header: Attribute

Row: Tuple

Table: Relation
Structure of relational databases
Basic structure

The account Relation The instructor Relation

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Fourth Edition and Sixth Edition
Structure of relational databases
Basic structure (contd.)

• Details of Account table


➢ D1: Set of all account numbers
➢ D2: Set of all branch numbers
➢ D3 : Set of all balances
➢ Any row of Account consists of three tuples (v1, v2, v3)

➢ Account is a subset of
D1 x D2 x … x Dn

➢ Table of n attributes must be a subset of


D1 x D2 x … x Dn-1 x Dn

• Mathematically, relation is a subset of a cartesian product of a list of domains


Structure of relational databases
Basic structure (contd.)

Tuple Variable whose domain is the set of all tuples


variable
Mathematical notation: tr
Tuples in relation r

t[account-number] = “A-101”
t[branch-number] = “Downtown”

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Fourth Edition


Structure of relational databases
Basic structure (contd.)

Sorted table

Ordering of
tuples
• Order of tuples is
irrelevant
• Example:Account
relation with
unordered tuples

Unsorted table

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Fourth Edition


Structure of relational databases
Basic structure (contd.)

Sorted table Unsorted table

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Sixth Edition


Structure of relational databases
Basic structure (contd.)

• Set of allowed values for each


Domain attribute is called the domain of the
attribute
• Attribute values are (normally)
required to be atomic
• Method of specifying a domain is to
specify a data type
• Several attributes to have same
domain. Example: customer-name
and employee-name have same
domain (set of person names)
Structure of relational databases
Basic structure (contd.)

Domain
• The special value null is a
member of every domain (value
is unknown or doesn’t exist)
• Null value causes complications
in the definition of many
operations
• Null values must be eliminated
Structure of relational databases
Database schema

Database schema
Logical design of database

Database

Database instance
Values of data in database at a
given instant of time
Structure of relational databases
Database schema (contd.)

Relation schema Relation instance

List of attributes and their Current values (relation instance) of a


corresponding domains relation
A1, A2, …, An are attributes
R = (A1, A2, …, An ) is a relation Containing specific set of rows.
schema
Example: customer-schema = Example: instructor relation has 12
(customer-name, tuples
customer-street, customer-city)
Corresponds to programming
Corresponds to programming language notion of a value of a
language notion of type definition variable

Doesn’t generally change May change with time


Structure of relational databases
Database schema (contd.)

The instructor relation The department relation

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Sixth Edition


Structure of relational databases
Database schema (contd.)

• Database consists of multiple relations


• Information about an enterprise is broken up into parts, with each
relation storing one part of the information
• Example
➢ account : Stores information about accounts
➢ depositor: stores information about which customer owns which
account
➢ customer : stores information about customers
• Storing all information as a single relation
➢ Example:
bank(account-number,balance,customer-name,..)
Drawbacks
• repetition of information (e.g. two customers own an account)
• the need for null values (e.g. represent a customer without an
account)
Structure of relational databases
Database schema (contd.)

The customer relation The depositor relation

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Fourth Edition


Structure of relational databases
Database schema (contd.)

The department relation

Schema for department: department (dept_name,building, budget)

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Sixth Edition


Structure of relational databases
Keys
Need
• To specify how tuples within a given relation are distinguished in
terms of attributes
• To uniquely identify the tuple
Structure of relational databases
Keys (contd.)

Superkey Candidate key Primary key

Set of one or more Extraneous


attributes of Candidate key
attributes, taken
superkeys used to identify
collectively,
tuples within a
identify uniquely a Minimal superkeys relation
tuple in the
relation Superkeys for Attributes are
which no proper never or very
subset of superkey rarely changed
Example:
ID attribute of Example:
instructor Both {ID} Example:
Combination of ID {name, ID
and name for dept_name}
instructor
Structure of relational databases
Keys (contd.)
Strong entity set
Primary key of the entity set
becomes the primary key of
the relation Attributes of weak
entity set

Primary key of
Weak entity set strong
Primary key of the relation entity set on which
Determine primary key for weak entity set
relation schema from consists of the union of the
primary key of the strong depends
primary keys of entity and
relationship sets entity set and the
discriminator of the weak Many-to-one:
entity set Primary key of
“many” entity set

One-to-one:
Relationship set
Primary key of
Union of the primary keys of either entity set
the related entity sets
becomes a super key of the Many-to-many:
relation union of the
primary keys
Structure of relational databases
Keys (contd.)
The instructor relation

Foreign key

• Referencing relation, r1 of
foreign key dependency
• Referenced relation, r2 of
foreign key The department relation
• Example:
• dept_name in instructor
is a foreign key from
instructor referencing
department, dept_name
is primary key of
department

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Sixth Edition


Structure of relational databases
Schema Diagram

• Representation of a database schema along with primary key and


foreign key dependency
• Explicit representation of foreign key unlike E-R diagram

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Fourth Edition


Structure of relational databases
Schema Diagram (contd.)

Reference: Silberschatz−Korth−Sudarshan, Database System Concepts, Sixth Edition


Structure of relational databases
Query languages
Query Language
Language in which user requests information from the database

Categories of query “Pure” query


languages languages

Procedural Relational Algebra

Tuple Relational
Non-procedural
Calculus

Domain Relational
Calculus

You might also like