Unit III - Relational Database Model
Unit III - Relational Database Model
4 HRS
1
Notes By: Raju Poudel (Mechi Multiple Campus)
Structure of RDBMS
A relational database is a type of database. It uses a structure that allows us to
identify and access data in relation to another piece of data in the database. Often,
data in a relational database is organized into tables.
A relational database management system (RDBMS) is a program that allows
you to create, update, and administer a relational database. Most relational
database management systems use the SQL language to access the database.
MySQL, SQL-Server, MS-Access, Oracle are some of popular RDBMS.
Examples of RDBMS structure:
2
Notes By: Raju Poudel (Mechi Multiple Campus)
Database Schema
A database schema is the skeleton structure that represents the logical view of the
entire database. It defines how the data is organized and how the relations among
them are associated. It formulates all the constraints that are to be applied on the
data.
A database schema defines its entities and the relationship among them. It
contains a descriptive detail of the database, which can be depicted by means of
schema diagrams. It’s the database designers who design the schema to help
programmers understand the database and make it useful.
A database schema can be divided broadly into two categories −
Physical Database Schema − This schema pertains to the actual storage of data
and its form of storage like files, indices, etc. It defines how the data will be stored
in a secondary storage.
Logical Database Schema − This schema defines all the logical constraints that
need to be applied on the data stored. It defines tables, views, and integrity
constraints. 3
Notes By: Raju Poudel (Mechi Multiple Campus)
Schema Diagram for Employee Database
4
Notes By: Raju Poudel (Mechi Multiple Campus)
Schema Diagram for Order Database
5
Notes By: Raju Poudel (Mechi Multiple Campus)
Schema Diagram for University Database
6
Notes By: Raju Poudel (Mechi Multiple Campus)
Keys
A DBMS key is an attribute or set of an attribute which helps you to identify a
row(tuple) in a relation(table).
They allow you to find the relation between two tables. Keys help you uniquely
identify a row in a table by a combination of one or more columns in that table.
1. Super key
A superkey is a group of single or multiple keys which identifies rows in a table. A
Super key may have additional attributes that are not needed for unique
identification.
9
Notes By: Raju Poudel (Mechi Multiple Campus)
Keys
4. Foreign key
A foreign key is a column which is added to create a relationship with another table.
Foreign keys help us to maintain data integrity and also allows navigation between
two different instances of an entity.
Every relationship in the model needs to be supported by a foreign key.
10
Notes By: Raju Poudel (Mechi Multiple Campus)
Keys
5. Composite key
A key which has multiple attributes to uniquely identify rows in
a table is called a composite key.
6. Alternate key
All the keys which are not primary key are called an alternate
key. It is a key which is currently not the primary key.
However, A table may have single or multiple choices for the
primary key.
11
Notes By: Raju Poudel (Mechi Multiple Campus)
Summary
12
Notes By: Raju Poudel (Mechi Multiple Campus)
Relational Algebra
Every database management system must define a query language to allow users to access
the data stored in the database.
Relational Algebra is a procedural query language used to query the database tables to access
data in different ways.
In relational algebra, input is a relation (table from which data has to be accessed) and output is
also a relation (a temporary table holding the data asked for by the user).
13
Notes By: Raju Poudel (Mechi Multiple Campus)
Relational Algebra Operations
The primary operations that we can perform using relational algebra are: Select, Project,
Union, Set Difference, Cartesian Product and Join.
14
Notes By: Raju Poudel (Mechi Multiple Campus)
Relational Algebra Operations
b) Project Operation (∏)
Project operation is used to project only a certain set of attributes of a relation. In simple words,
If you want to see only the names all of the students in the Student table, then you can use
Project Operation.
It will only project or show the columns or attributes asked for, and will also remove duplicate
data from the columns.
For example,
∏Name, Age(Student)
Above statement will show us only the Name and Age columns for all the rows of data in
Student table.
• Relational algebra expressions
15
Notes By: Raju Poudel (Mechi Multiple Campus)
Relational Algebra Operations
c) Union Operation (∪)
This operation is used to fetch data from two relations(tables).
For this operation to work, the relations(tables) specified should have same number of
attributes(columns) and same attribute domain. Also the duplicate rows are automatically
eliminated from the result.
Syntax: A ∪ B where A and B are relations.
For example, if we have two tables RegularClass and ExtraClass, both have a column student
to save name of student, then,
∏Student(RegularClass) ∪ ∏Student(ExtraClass)
Above operation will give us name of Students who are attending both regular classes and
extra classes, eliminating repetition.
16
Notes By: Raju Poudel (Mechi Multiple Campus)
Relational Algebra Operations
d) Set Difference (-)
This operation is used to find data present in one relation and not present in the second
relation. This operation is also applicable on two relations, just like Union operation.
Syntax: A – B where A and B are relations.
For example, if we want to find name of students who attend the regular class but not the extra
class, then, we can use the below operation:
∏Student(RegularClass) - ∏Student(ExtraClass)
18
Notes By: Raju Poudel (Mechi Multiple Campus)