Relational Model
Relational Model
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.
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
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.
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)
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.
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.
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.
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.
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:
Notation: σ p(r)
Relational Algebra
1. Select Operation:
Notation: σ p(r)
Where:
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 ∏.
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.
Notation: R ∪ S
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.
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(ρ)