Relational Model

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 46

Relational Model

Relational Model
 After designing the conceptual model of Database using ER diagram, we need to convert the
conceptual model in to the relational model which can be implemented using any RDMBS
languages like Oracle SQL, MySQL etc.

 Relational Model represents the logical view of how data is stored in the Relational
Databases.

 The data and relationships are represented by collection of inter-related tables.

 Each table is a group of column and rows, where column represents attribute of an entity and
rows represents records.
Components of Relational Model
 Tables

In the Relational model the, relations are saved in the table format. It is stored along with
its entities. A table has two properties rows and columns. Rows represent records and
columns represent attributes.

 Attribute:

Each column in a Table. Attributes are the properties which define a relation. e.g.,
Student_Rollno, NAME,etc.

 uple

It is nothing but a single row of a table, which contains a single record.


Components of Relational Model
 Relation Schema:
A relation schema represents the name of the relation with its attributes.
 Degree:

The total number of attributes which in the relation is called the degree of the relation.
 Cardinality: Total number of rows present in the Table.

 Relation:

A relation in relational data model represents the respective attributes and the correlation among
them.
 Domain

Domain is a set of values which is indivisible i.e. value for each attributerepresent in the table contains soe
specific domain in which the value needs to lie. For example, the value of dob must be greater than
zero.As, it can not be –ve. This is called domain of an attribute .
Components of Relational Model
Relational Database Schema
 A relational schema for a database is an outline of how data is organized.

 It can be a graphic illustration or another kind of chart used by programmers to


understand how each table is laid out, including the columns and the types of
data they hold and how tables connect. It can also be written in SQL code.

 In a schema diagram, all databse tables are designated with unique columns and
special features, eg. Primary Key(PK), foreign key(FK) or not null etc.
Relational Database Schema
 Example : Schema of College Management System

Department(Dept_id,Dept_name,Dept_block_no)

Student(Stud_id, Stud_name, Stud_address, Dept_id)

Staff(Staff_id, Staff_name, Dept_id)

Subject(Sub_id, Sub_name, Sub_code,Staff_id)

Marks(Marks_obtain, Sub_id,Stud_id)
Relational Database Schema
 Example : Schema Diagram for Company Management System
Relational Database Schema
 Example
Relational Integrity constraints
 Relational Integrity constraints is referred to conditions which must be present
for a valid relation. These integrity constraints are derived from the rules in the
mini-world that the database represents.

 There are many types of integrity constraints. Constraints on the Relational


database management system is mostly divided into three main categories are:

1. Domain constraints
2. Key constraints
3. Referential integrity constraints
Domain Constraints
 Domain constraints can be violated if an attribute value is not appearing in the
corresponding domain or it is not of the appropriate data type.

 Domain constraints specify that within each tuple, and the value of each
attribute must be unique. This is specified as data types which include standard
data types integers, real numbers, characters, Booleans, variable length strings,
etc.
Key constraints
 An attribute that can uniquely identify a tuple in a relation is called the key of the table. The
value of the attribute for different tuples in the relation has to be unique.

 Example:
In the given table, CustomerID is a key attribute of Customer Table. It is most likely to have
a single key for one customer, CustomerID =1 is only for the CustomerName =" Google".
Referential integrity constraints
 Referential integrity constraints is base on the concept of Foreign Keys. A foreign key is an
important attribute of a relation which should be referred to in other relationships.
Referential integrity constraint state happens where relation refers to a key attribute of a
different or same relation. However, that key element must exist in the table.

In the example, we have 2 relations, Customer and Billing.


Tuple for CustomerID =1 is referenced twice in the relation
Billing. So we know CustomerName=Google has billing amount
$300
Best Practices for creating a Relational Model
 Data need to be represented as a collection of relations

 Each relation should be depicted clearly in the table

 Rows should contain data about instances of an entity

 Columns must contain data about attributes of the entity


 Cells of the table should hold a single value

 Each column should be given a unique name


 No two rows can be identical
 The values of an attribute should be from the same domain
Advantages of Relational model
 Simplicity: A relational data model is simpler than the hierarchical and network model.
 Structural Independence: The relational database is only concerned with data and not
with a structure. This can improve the performance of the model.
 Easy to use: The relational model is easy as tables consisting of rows and columns is quite
natural and simple to understand
 Query capability: It makes possible for a high-level query language like SQL to avoid
complex database navigation.
 Data independence: The structure of a database can be changed without having to change
any application.
 Scalable: Regarding a number of records, or rows, and the number of fields, a database
should be enlarged to enhance its usability.
Disadvantages of Relational model
 Few relational databases have limits on field lengths which can't be exceeded.

 Relational databases can sometimes become complex as the amount of data


grows, and the relations between pieces of data become more complicated.

 Complex relational database systems may lead to isolated databases where the
information cannot be shared from one system to another.
Query Langauage
 Query language (QL) refers to any computer programming language that
requests and retrieves data from database by sending queries.

 It works on user entered structured and formal programming command based


queries to find and extract data from host databases.

 Query language may also be termed database query language.


Query Language
 There are two types of Query languages:
Query Language
 There are two types of Query languages:
1. Procedural :
In a procedural language the user instructs the system to perform a sequence of
operations on the database to compute the desired result. For example, Relational
Algebra.

For example – Let’s take a real world example to understand the procedural language, you are asking
your younger brother to make a cup of tea, if you are just telling him to make a tea and not telling the
process then it is a non-procedural language, however if you are telling the step by step process like switch
on the stove, boil the water, add milk etc. then it is a procedural language.
Query Language
2. Non –procedural:

In Non-procedural query language, user instructs the system to produce the desired
result without telling the step by step process. Here users tells what data to be
retrieved from database but doesn’t tell how to retrieve it.

For example tuple relational calculus, domain relational calculus, SQL etc .
Relational Algebra
 It 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 ne either unary or binary.

 They accept relations as their input and yield relations as their output.

 Relational algebra is performed recursively ion a relation and intermediate results re also
considered relations.
Relational Algebra
Types of operations in relational algebra:

1. Basic Operations

2. Derived Operations
Relational Algebra
Basic/Fundamental Operations:

1. Select (σ)
2. Project (∏)
3. Union (∪)
4. Set Difference (-)
5. Cartesian product (X)
6. Rename (ρ)
Relational Algebra

Derived Operations:

1. Natural Join (⋈)


2. Left, Right, Full outer join (⟕, ⟖, ⟗)
3. Intersection (∩)
4. Division (÷)
Relational Algebra
1. Select Operation:

 The select operation selects tuples that satisfy a given predicate.

 It is denoted by sigma (σ).

Notation: σ p(r)
Relational Algebra
1. Select Operation:

 The select operation selects tuples that satisfy a given predicate.

 It is denoted by sigma (σ).

Notation: σ p(r)
Where:

σ is used for selection prediction


r is used for relation
p is used as a propositional logic formula which may use connectors like: AND OR and NOT. These
relational can use as relational operators like =, ≠, ≥, <, >, ≤.
Relational Algebra
1. Select Operation:
Relational Algebra
1. Select Operation:
Relational Algebra
2. Project Operation:

 This operation shows the list of those attributes that we wish to appear in the result. Rest of
the attributes are eliminated from the table.

 It is denoted by ∏.

Notation: ∏ A1, A2, An (r)

Where
A1, A2, A3 is used as an attribute name of relation r.
Relational Algebra
2. Project Operation:
Relational Algebra
2. Project Operation:
Relational Algebra
3. Union Operation:
 Union operation in relational algebra is same as union operation in set theory.

 Suppose there are two tuples R and S. The union operation contains all the tuples that
are either in R or S or both in R & S.

 It eliminates the duplicate tuples. It is denoted by ∪.

Notation: R ∪ S

A union operation must hold the following condition:

 R and S must have the attribute of the same number.


 Duplicate tuples are eliminated automatically.
Relational Algebra
3. Union Operation:
Relational Algebra
3. Union Operation:
Relational Algebra
3. Union Operation:
Relational Algebra
3. Union Operation(U):

Note:
As you can see there are no duplicate names present in the output even though we had few
common names in both the tables, also in the COURSE table we had the duplicate name itsel
Relational Algebra
4. Set Intersection(∩ ):

 Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in both R & S.

 It is denoted by intersection ∩.

Notation: R ∩ S
Relational Algebra
4. Set Intersection(∩ ):
Relational Algebra
5. Set Difference (-):

 Suppose there are two tuples R and S. The set intersection operation contains all tuples that
are in R but not in S.

 It is denoted by intersection minus (-).

Notation: R - S
Relational Algebra
5. Set Difference (-):
Relational Algebra
6. Cartesian product (X):

 The Cartesian product is used to combine each row in one table with each row in the other
table. It is also known as a cross product.

 It is denoted by X.

Notation: E X D
Relational Algebra
6. Cartesian product (X):
Relational Algebra
6. Cartesian product (X):
Relational Algebra
7. Rename Operation(ρ)

 The rename operation is used to rename the output relation.

 It is denoted by rho (ρ).

Rename (ρ) Syntax:


ρ(new_relation_name, old_relation_name)
Relational Algebra
7. Rename Operation(ρ)
Relational Algebra
7. Rename Operation(ρ)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy