Dbms Unit3 Part1
Dbms Unit3 Part1
Relational Model
&
Storage Indexing
* 1
Relational Model
RELATIONAL MODEL: Introduction to Relational
Model, Basic Structure, Database Schema, Keys,
Relational Algebra and Relational Calculus.
* 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:
* 4
Cont….
• Relation schema − A relation schema describes the
relation name (table name), attributes, and their names.
* 5
Basic Structure of Relational Model
* 6
Features of the relational model
* 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.
* 9
Database Instances
• Definition of instance: The data stored in database at a
particular moment of time is called instance of 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.
* 11
Formal Relational Query Languages
• Two mathematical Query Languages form the basis for
“real” languages (e.g. SQL), and for implementation:
* 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)
* 20
Cross-Product (Cartesian Product)
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)
24
Intersection
• It performs binary intersection between two given
relations and is defined as
• r s = { t | t ∈ r and t ∈ s}
25
Join
• Equi-Join: A special case of condition join where
the condition c contains only equalities.
* 26
Joins: used to combine relations
• Condition 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
* 30
Relational Calculus
* 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.
* 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