0% found this document useful (0 votes)
4 views35 pages

Dbms Unit3 Part1

The document provides an overview of the Relational Model, including its basic structure, database schemas, and key concepts such as tables, tuples, and keys. It also discusses storage and indexing techniques, relational algebra, and relational calculus as query languages for manipulating and retrieving data. The relational model is highlighted for its simplicity, powerful theoretical foundation, and ease of use with SQL.

Uploaded by

nayana.datla2005
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)
4 views35 pages

Dbms Unit3 Part1

The document provides an overview of the Relational Model, including its basic structure, database schemas, and key concepts such as tables, tuples, and keys. It also discusses storage and indexing techniques, relational algebra, and relational calculus as query languages for manipulating and retrieving data. The relational model is highlighted for its simplicity, powerful theoretical foundation, and ease of use with SQL.

Uploaded by

nayana.datla2005
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/ 35

Unit - III

Relational Model
&
Storage Indexing

* 1
Relational Model
RELATIONAL MODEL: Introduction to Relational
Model, Basic Structure, Database Schema, Keys,
Relational Algebra and Relational Calculus.

Storage and Indexing: File Organizations and


Indexing-Overview of Indexes, Types of Indexes,
Index Data Structures, Tree structured Indexing,
Hash based Indexing.

* 2
Introduction to Relational Model
• Relational data model is the primary data model, which is
used widely around the world for data storage and
processing.
• This model is simple and it has all the properties and
capabilities required to process data with storage
efficiency.

* 3
Terminology Used in Basic Structure of Relational Model:

• Tables − In relational data model, relations are saved in


the format of Tables. This format stores the relation among
entities.
• A table has rows and columns, where rows represents
records and columns represent the attributes.

• Tuple − A single row of a table, which contains a single


record for that relation is called a tuple.

• Relation instance − A finite set of tuples in the relational


database system represents relation instance. Relation
instances do not have duplicate tuples.

* 4
Cont….
• Relation schema − A relation schema describes the
relation name (table name), attributes, and their names.

• Relation key − Each row has one or more attributes,


known as relation key, which can identify the row in the
relation (table) uniquely.

• Attribute domain − Every attribute has some pre-defined


value scope, known as attribute domain.

* 5
Basic Structure of Relational Model

• A relational database is a collection of tables.


– Each table has a unique name.
– Each table consists of multiple rows.
– Each row is a set of values that by definition are related
to each other in some way;
– these values conform to the attributes or columns of the
table.

* 6
Features of the relational model

– Conceptually simple: the fundamentals are intuitive and easy to


pick up.
– Powerful underlying theory: the relational model is the only
database model that is powered by formal mathematics, which
results in excellent dividends when developing database
algorithms and techniques.
– Easy-to-use database language: though not formally part of the
relational model, part of its success is due to SQL, the de facto
language for working with relational databases.

* 7
Database Schemas
• Definition of schema: Design of a database is called the schema.
Schema is of three types:
1. Physical schema
2. logical schema
3. view schema.
• The design of a database at physical level is called physical schema,
how the data stored in blocks of storage is described at this level.

• Design of database at logical level is called logical schema,


programmers and database administrators work at this level, at this
level data can be described as certain types of data records gets stored
in data structures, however the internal details such as implementation
of data structure is hidden at this level (available at physical level).

• Design of database at view level is called view schema. This generally


describes end user interaction with database systems.
* 8
Example
For example: In the following diagram,
we have a schema that shows the
relationship between three tables:
Course, Student and Section.

The diagram only shows the design of


the database, it doesn’t show the data
present in those tables. Schema is only a
structural view(design) of a database as
shown in the diagram .

* 9
Database Instances
• Definition of instance: The data stored in database at a
particular moment of time is called instance of database.

• Database schema defines the variable declarations in


tables that belong to a particular database; The value of
these variables at a moment of time is called the instance of
that database.

• For example: lets say we have a single table student in the database, today the
table has 100 records, so today the instance of the database has 100 records.
Lets say we are going to add another 100 records in this table by tomorrow so
the instance of database tomorrow will have 200 records in table. In short, at a
particular moment the data stored in database is called the instance, that
changes over time when we add or delete data from the database.

* 10
Relational Query Languages
• Relational database systems are expected to be equipped
with a query language that can assist its users to query
the database instances.
• There are two kinds of query languages − relational
algebra and relational calculus.

• Query languages: Allow manipulation and retrieval of


data from a database.
• Query Languages != programming languages!
– QLs not intended to be used for complex calculations.
– QLs support easy, efficient access to large data sets.

* 11
Formal Relational Query Languages
• Two mathematical Query Languages form the basis for
“real” languages (e.g. SQL), and for implementation:

– Relational Algebra: More operational (procedural),


very useful for representing execution plans.

– Relational Calculus: Lets users describe what they


want, rather than how to compute it: Non-operational,
declarative.

* 12
Relational Algebra
• Relational algebra is a procedural query language, which
takes instances of relations as input and yields
instances of relations as output.
• It uses operators to perform queries. An operator can be
either unary or binary.
• They accept relations as their input and yield relations as
their output.
• Relational algebra is performed recursively on a relation
and intermediate results are also considered relations.

* 13
Example Instances
• “Sailors” and “Reserves”
S1
relations for our examples.

R1

S2

14
Relational Algebra
• Basic operations:
– Projection ( ) Deletes unwanted columns from relation.
– Selection ( ) Selects a subset of rows from relation.
– Cross-product ( ) Allows us to combine two relations.
– Set-difference ( ) Tuples in reln. 1, but not in reln. 2.
– Union ( ) Tuples in reln. 1 and in reln. 2.
• Additional operations:
– Intersection, join, division, renaming

* 15
Projection
• Notation − ∏A1, A2, …An (r)
• Where A1, A2 , An are attribute names of relation r.
• Deletes attributes that are not in projection list.
• Schema of result contains exactly the fields in the
projection list, with the same names that they had in the
input relation.
• Projection operator eliminates duplicates.

16
Example:

17
Selection
• Selects rows that satisfy selection condition.
• Notation − σp(r)
• Where σ stands for selection predicate and r stands for
relation. p is prepositional logic formula which may use
connectors like and, or, and not. These terms may use
relational operators like − =, ≠, ≥, < , >, ≤.
• No duplicates in result
• Schema of result identical to schema of input relation.

18
Example:

19
Cross-Product (Cartesian Product)

• Combines information of two different relations into


one.
• Notation − r Χ s
• Where r and s are relations and their output will be
defined as −
r Χ s = { q t | q ∈ r and t ∈ s}
• Output − Yields a relation, which shows all the
books and articles.

* 20
Cross-Product (Cartesian Product)

• Each row of S1 is paired with each row of R1.


• Result schema has one field per field of S1 and
R1, with field names `inherited’ if possible.
– Conflict: Both S1 and R1 have a field called sid.

▪ Renaming operator (rho):


* 21
Set Difference
The result of set difference operation is tuples, which are
present in one relation but are not in the second relation.
Notation: r − s

22
Union
• It performs binary union between two given
relations and is defined as −
Notion − r U s
• Where r and s are either database relations

23
Union (contd.,)
• For a union operation to be valid, the following
conditions must hold −
• r, and s must have the same number of attributes.
• Attribute domains must be compatible.
• Duplicate tuples are automatically eliminated.

• Ex:
• ∏ author (Books) ∪ ∏ author (Articles)

• Output − Projects the names of the authors who have


either written a book or an article or both.

24
Intersection
• It performs binary intersection between two given
relations and is defined as
• r s = { t | t ∈ r and t ∈ s}

• Where r and s are either database relations

25
Join
• Equi-Join: A special case of condition join where
the condition c contains only equalities.

• Result schema similar to cross-product, but only


one copy of fields for which equality is specified.

* 26
Joins: used to combine relations

• Condition Join:

• Result schema same as that of cross-product.


• Fewer tuples than cross-product, might be able to
compute more efficiently
• Sometimes called a theta-join.

* 27
Division
• As the name of this operation implies, it involves
dividing one relation by another.
• It is denoted as ÷.

* 28
Examples of Division A/B

B1
B2
B3

A A/B1 A/B2 A/B3


* 29
Relational Calculus

* 30
Relational Calculus

• Relational calculus is a non-procedural query


language.

• In the non-procedural query language, the user is


concerned with the details of how to obtain the
end results.

• The relational calculus tells what to do but never


explains how to do.

* 31
Types of Relational calculus:

* 32
1. Tuple Relational Calculus (TRC)
• The tuple relational calculus is specified to select the tuples
in a relation. In TRC, filtering variable uses the tuples of a
relation.
• The result of the relation can have one or more tuples.
Notation:
{T | P (T)} or {T | Condition (T)}
– Where, T is the resulting tuples
– P(T) is the condition used to fetch T.
For example:
{ T.name | Author(T) AND T.article = 'database' }
Output: This query selects the tuples from the AUTHOR
relation. It returns a tuple with 'name' from Author who
has written an article on 'database'.

* 33
2. Domain Relational Calculus (DRC)
• The second form of relation is known as Domain
relational calculus.

• In domain relational calculus, filtering variable uses the


domain of attributes.

• Domain relational calculus uses the same operators as


tuple calculus. It uses logical connectives ∧ (and), ∨
(or) and ┓ (not).

• It uses Existential (∃) and Universal Quantifiers (∀)


to bind the variable.

* 34
• Notation:
• { a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}
Where
a1, a2 are attributes
P stands for formula built by inner attributes

• For example:
{< article, page, subject > | ∈ javatpoint ∧ subject = 'database
'}
• Output:
This query will yield the article, page, and subject from the
relational javatpoint, where the subject is a database.

* 35

You might also like