DBMS Lectures Compile
DBMS Lectures Compile
(DBMS)
1
Number of Credits in this Course
• Lecture – 3 Credits
• Tutorial – 0 Credits
• Lab – 1 Credit
-------------------------------
Total – 4 Credits
Evaluation Scheme
Components Weightage
Quizzes 40 Marks
Class Participation 10 Marks
150 Marks for Theory
Mid-Term Exam 30 Marks
End-Term Exam 70 Marks
Continuous Lab Evaluation 100 Marks
Books
• Fundamentals of database systems (Ramez Elmsari · Shamkant B. Navathe)
• Database System Concepts (Avi Silberschatz · Henry F. Korth · S. Sudarshan)
Outlines
• Introduction of database
• File processing system
• Disadvantages of file processing system
• Transition to Database management system
• Characteristics of the database management system
• MCQs
• Summary
4
What is Database Management System (DBMS)?
• Data - Fact that can be recorded or stored
• e.g. Person Name, Age, Gender and Weight etc.
• Database - Collection of logically related data (i.e., record)
• Traditional Database (TDB): Text and Number
• Multimedia Database (MDP): Video, Speech, song, movie, etc.
• Geographic Information System (GIS): Images of earth
• Real-Time Database (RTD): Production, Supermarket – varying products data
• Data Warehouse (DW): Huge and Historical Data.
• Database Management System (DBMS) – Set of programs or software used to define, manipulate, retrieve and
manage data in a database.
• e.g. MS SQL Server, Oracle, My SQL, SQLite, MongoDB etc.
6
Database System vs. File-processing system
• A file processing system is a software that stores and manage files in computer
hard disk.
• It allows access to single files or tables at a time.
• Data is directly stored in set of files.
• It contains flat files that have no relation to other files.
• File system consists of different files which are grouped into directories.
The directories further contain other folders and files.
• E.g. NTFS (New Technology File System), EXT (Extended File System)
• DBMS
• A Database Management System (DBMS) is a software that allows user to efficiently define,
create, maintain and share databases.
• E.g. Oracle, MySQL, MS SQL server, IBM DB2, MS Access, dBASE, SQLite, etc.
7
How it works?
Accounts HR Production
Data Data Data
Each department maintain their own set of data. There is no link between those data pools.
Example for file-processing system
• University records,
• The grade reporting office,
• may keep files of students and their grades.
• Programs to print a student’s transcript and to enter new grades.
• The accounting office,
• may keep track of students’ fees and their payments.
• Although both users are interested in data about students,
• Each user maintains separate files—and programs to manipulate
these files.
• This make redundancy in defining and storing data
9
Disadvantages file-processing system
• Data redundancy and inconsistency
• Redundancy occurs when same piece of the data is held in two or more separate places.
• Inconsistency occurs when similar data is kept in different format or values at two or more separate places.
• Data redundancy leads to data inconsistency.
• All copies may not be updated properly.
• Difficulty in accessing data
• It does not allow needed data to be retrieved in a convenient and efficient manner .
• More responsive data-retrieval systems are required .
• Data isolation
• Data is scattered in various files, and files may be in different formats.
• It is very difficult to handle.
• Integrity problems
• The data values stored in the database must satisfy certain types of constraints.
• It is difficult to change the programs , when new constraints are added.
10
Disadvantages file-processing system
• Atomicity problems
• It is essential in database that either complete query to be executed, or none, which means
either all the operations in a transaction executes or none.
• It is difficult to ensure atomicity in a conventional file-processing system.
• Failures may leave database in an inconsistent state with partial updates carried out.
• Concurrent-access anomalies
• For faster response, many systems allow multiple users to update the data simultaneously.
• In such an environment, interaction of concurrent updates is possible and may result in
inconsistent data.
• Security problems
• Not every user of the database system should be able to access all the data.
• As application programs are added to the file-processing system in an ad hoc manner,
enforcing such security constraints is difficult.
Data
Advantages of DBMS over File System
• No Redundant Data: Redundancy removed by data normalization. No data duplication saves
storage and improves access time.
• Data Consistency and Integrity: The root cause data inconsistency is data redundancy, since data
normalization takes care of the data redundancy, data inconsistency also been taken care of as
part of it.
• Data Security: It is easier to apply access constraints in database systems so that only authorised
user is able to access it. Each user has a different set of access thus data is secured form the
issues such as identity theft, data leaks and misuse of data.
• Privacy: Limited access means privacy of data.
• Easy access to data: Database systems manage data in such a way so that the data is easily
accessible with fast response times.
• Easy recovery: Since database systems keep the backup of data, its easier to do a full recovery of
data in case of failure.
• Flexible: Database systems are more flexible than file processing systems.
2
Characteristics of the Database Approach
• In the database approach, a single repository maintains data.
• It should be accessed by various users repeatedly through queries, transactions,
and application programs.
• The main characteristics of the database approach are:
• Self-describing nature of a database system
• Insulation between programs and data, and data abstraction
• Support of multiple views of the data
• Sharing of data and multiuser transaction processing
3
Self-Describing Nature of a Database System
• A fundamental characteristic of the database approach is
• It should contain not only the database itself but also contains its complete definition.
• The definition contains
• The structure of each file, the type and storage format of each data item, and various constraints
on the data.
• This information is called meta-data.
4
Example of a
Database:
5
Self-Describing Nature
6
Insulation between Programs and Data
• In traditional file processing, the structure of data files is embedded in the application
programs.
• So any changes to the structure of a file may require changing all programs that access
that file.
• In DBMS, structure of data files is stored separately from the access programs.
7
Data Abstraction
• An operation (also called a function or method) is specified in two parts.
• The interface (or signature) of an operation includes the operation name and the data types of its
arguments (or parameters).
• The implementation (or method) of the operation is specified separately and can be changed
without affecting the interface.
• User application programs can operate on the data by invoking these operations through their
names and arguments, regardless of how the operations are implemented.
• This may be termed program-operation independence.
• The characteristic that allows program-data independence and program-operation independence
is called data abstraction.
• A DBMS provides users with a conceptual representation of data that does not include many of the
details of how the data is stored or how the operations are implemented.
8
Support of Multiple Views of the Data
• A database typically has many types of users, each of whom may require a
different perspective or view of the database.
• A view may be a subset of the database or it may contain virtual data that is
derived from the database files.
• But this view is not explicitly stored.
9
Basis File System DBMS
File system is a software that manages and organizes
1. Structure DBMS is a software for managing the database.
the files in a storage medium within a computer.
2. Data Redundancy Redundant data can be present in a file system. In DBMS there is no redundant data.
It doesn’t provide backup and recovery of data if it is It provides backup and recovery of data even if it is
3.Backup and Recovery
lost. lost.
4. Query processing There is no efficient query processing in file system. Efficient query processing is there in DBMS.
File systems provide less security in comparison to DBMS has more security mechanisms as compared to
7.Security Constraints
DBMS. file system.
8.Cost It is less expensive than DBMS. It has a comparatively higher cost than a file system.
10
DBMS Architecture
• The DBMS design depends upon its architecture. The basic client/server architecture is used to
deal with a large number of PCs, web servers, database servers and other components that are
connected with networks.
• This architecture consists of many PCs and a workstation which are connected via the network.
• DBMS architecture depends upon how users are connected to the database to get their
request done.
Types of DBMS Architecture:
Types of DBMS Architectures
1-Tier Architecture:
• The database is directly available to the user.
• Any changes done here will directly be done on the database itself. It doesn't provide a handy tool for
end users.
• The 1-Tier architecture is used for development of the local application, where programmers can
directly communicate with the database for the quick response.
2-Tier Architecture:
• The 2-Tier architecture is same as basic client-server. In the two-tier architecture, applications on the
client end can directly communicate with the database at the server side. For this interaction, API's
like: ODBC, JDBC are used.
• The user interfaces and application programs are run on the client-side. The server side is responsible to
provide the functionalities like: query processing and transaction management.
• To communicate with the DBMS, client-side application establishes a connection with the server side.
Types of DBMS Architectures
2-Tier Architecture:
Ramez Elmasri and Shamkant B. Navathe. 1989. Fundamentals of database systems. Benjamin-Cummings Publishing Co., Inc., USA.
Data Models
• A Data Model in DBMS is the concept of tools that are developed to summarize the
description of the database.
• It defines how the logical structure of a database is modeled.
• Data Models are fundamental entities to introduce abstraction in a DBMS.
• It defines how data is connected to each other and how they are processed and stored
inside the system.
• A Data Model is collection of conceptual tools for describing:
• Data
• Data Relationships
• Data Semantics
• Consistency Constraints
Types of Data Model
• Relational Model
• Entity-Relationship Model
• Object-based Data Model
• Semi-Structured Data Model
• Hierarchical Model
• Network Model
7
Relational Model
• Relational Model is the most widely used model.
• In this model, the data is maintained in the form of a two-dimensional tables called relation.
• All the information is stored in the form of row and columns, where column represents attributes and row
represents records or tuples.
• Features:
• Simple
• Scalable
• Structural Independence
E-R Model
• Entity-Relationship Model or simply ER
Model is a high-level data model
diagram
• In this model, we represent the real-
world problem in the pictorial form.
• It is also very easy for the developers to
understand the system by just looking at
the ER diagram.
• We use the ER diagram as a visual tool
to represent an ER Model.
• Features:
• Graphical Representation for Better
Understanding
• Helps to Design Database
Object-Based Model
• Real-world problems are more closely represented through the object-based i.e. object-oriented data model.
• Both the data and relationship are present in a single structure known as an object.
• In this model, two are more objects are connected through links. We use this link to relate one object to
other objects.
Hierarchical and Network Model
• Organizes the data in the hierarchical tree structure • Extension of the hierarchical model
• Hierarchy starts from the root and expands in the form of a tree
• Record can have more than one parent.
• Features:
• Features:
• One-to-many relationship
• Ability to Merge more Relationships
• Parent-Child Relationship
• Many paths
• Deletion Problem
• Circular Linked List
• Pointers
Data Models
• Data models describes a set of concepts
• Structure of a database
• Elements and their data types
• Records consisting of groups of elements
• Relationships among the records
• Operations for manipulating these structures
• Retrievals and updates
• Certain constraints that the database should obey
Categories of Data Models
• Conceptual (high-level) data models:
• Provide concepts that are close to the way many users perceive data.
• Entity Relationship (ER) Diagram comes under this model.
• Physical (low-level, internal) data models:
• Describe details of how data is stored in the computer.
• These are usually specified in an ad-hoc manner through DBMS design
• Implementation (representational) data models:
• Provide concepts that fall between the above two
• It is used by many commercial DBMS implementations (e.g. relational data models)
Database Schema
Ramez Elmasri and Shamkant B. Navathe. 1989. Fundamentals of database systems. Benjamin-Cummings Publishing Co., Inc., USA.
Example of a Database Schema
Ramez Elmasri and Shamkant B. Navathe. 1989. Fundamentals of database systems. Benjamin-Cummings Publishing Co., Inc., USA.
Database State or Instance
• The data in the database at a particular moment in time is called a
database state or snapshot.
• It changes every time we add new data in database.
• It is also called the current set of occurrences or instances in
the database.
• The term instance is also applied to individual database components, e.g.
record instance, table instance, entity instance.
• A state that satisfies the structure and constraints of the database is
called valid state.
Example of a database state
Ramez Elmasri and Shamkant B. Navathe. 1989. Fundamentals of database systems. Benjamin-Cummings Publishing Co., Inc., USA.
Three-Schema Architecture
• Defines DBMS schemas at three levels:
• Internal schema at the internal level to describe physical storage structures and
access paths (e.g indexes).
• Typically uses a physical data model.
• Conceptual schema at the conceptual level to describe the structure and constraints
for the whole database for a community of users.
• The conceptual schema hides the details of physical storage structures.
• Uses a conceptual or an implementation data model.
• External schemas (view schemas) describes the database part that a particular user
group is interested and hides the remaining database from that user group.
• The view schema describes the end user interaction with database systems.
• Usually uses the same data model as the conceptual schema.
Three-Schema Architecture
Three-Schema Architecture
• Mappings among schema levels are needed to transform requests
and data.
• Programs refer to an external schema, and are mapped by the DBMS
to the internal schema for execution.
• Data extracted from the internal schema is reformatted to match the
user’s external view
• e.g. formatting the results of an SQL query for display in a Web page.
9
Data Independence
• The ability to modify the schema at one level of the database system without
altering the schema at the next higher level.
11
Levels of Abstraction
12
Three Levels of Abstraction
• At View Level: User just interact with system using GUI. They are not
aware of how the data is stored.
13
Basic concepts
} What is Database Design?
Ê Database Design is a collection of processes that facilitate the designing, development, implementation and
maintenance of enterprise database management systems.
} What is E-R diagram?
Ê E-R diagram: (Entity-Relationship diagram)
Ê It is graphical (pictorial) representation of database.
Ê It uses different types of symbols to represent different objects of database.
Entity
} An entity is a person, a place or an object.
Entity Name
} An entity is represented by a rectangle which contains the name of an entity.
} Entities of a college database are: Symbol
Ê Student
Ê Professor/Faculty
Ê Course
Ê Department
Student Faculty Course
Ê Result
Ê Class
Ê Subject
Relationship
Name
Symbol
Each and every entity must have one primary key attribute.
Relationship between 2 entities is called binary relationship.
Ternary Relationship
ProjectID Project Name
Project
Middle name
Types of Attributes
Roll No Phone No
Types of Attributes
Middle
Name
First Name Last Name
Single
Simple
Value
RollNo Name Composite Apartment
Derived Composite
Multiple Stored
Value
Phone No Birth Date Area
Exercise
Draw an E-R diagram of Banking Management System.
Draw an E-R diagram of Hospital Management System.
Draw an E-R diagram of College Management System.
Take only 2 entities
Keep proper relationship between two entities
Use all types of attributes
Descriptive Attribute
Attribute of the relationship is called descriptive attribute.
Descriptive
Attribute
Issue
RollNo Name Date BookNo Name
Domain of multi-valued attribute is the subset of value from the basic domain.
Null Attribute: In some cases a particular entity may not have some applicable value for an
attribute.
Role
Roles are indicated by labeling the lines that connect diamonds (relationship) to rectangles
(entity).
The labels “Coordinator” and “Head” are called roles; they specify Faculty entities interact with
whom via Reports_To relationship set.
Role labels are optional, and are used to clarify semantics (meaning) of the relationship.
EmpID Name
Coordinator
Faculty Reports_To
Head
Branch Experience
Recursive Relationship
An Entity set related to itself is called recursive relationship.
Recursive Relationship Set
The same entity participates in a relationship set more than once then it is called recursive
relationship set.
FacID FName DeptID DName
Post Recursive
Relationship
FName Post Set DName
Ajay Professor Prof. Computer
Harish Professor Civil
Ramesh HOD Mechanical
Mapping Cardinality (Cardinality Constraints)
It represents the number of entities of another entity set which are connected to an entity
using a relationship set.
For a binary relationship set the mapping cardinality must be one of the following types:
One to One
One to Many
Many to One
Many to Many
One-to-One relationship (1 – 1)
An entity in A is associated with only one entity in B and an entity in B is associated with only
one entity in A.
C3 L3
A B
Example: A customer is connected with only one loan using the relationship borrower and a
loan is connected with only one customer using borrower.
One-to-Many relationship (1 – N)
An entity in A is associated with more than one entities in B and an entity in B is associated
with only one entity in A.
C3 L3
A B
L4
Example: A loan is connected with only one customer using borrower and a customer is
connected with more than one loans using borrower.
Many-to-One relationship (N – 1)
An entity in A is associated with only one entity in B and an entity in B is associated with more
than one entities in A.
C3 L3
A B
C4
Example: A loan is connected with more than one customer using borrower and a customer is
connected with only one loan using borrower.
Many-to-Many relationship (N – N)
An entity in A is associated with more than one entities in B and an entity in B is associated
with more than one entities in A.
C3 L3
A B
C4 L4
Example: A customer is connected with more than one loan using borrower and a loan is
connected with more than one customer using borrower.
Mapping Cardinality (Cardinality Constraints) [Exercise]
Draw an E-R diagram and specify which type of mapping cardinality will be there in the
following examples:
Each customer has only one account in the bank and each account is held by only one customer. [single
account]
Each customer has only one account in the bank but an account can be held by more than one customer.
[joint account]
A customer may have more than one account in the bank but each account is held by only one customer.
[multiple accounts]
A customer may have more than one account in the bank and each account is held by more than one
customer. [join account as well as multiple accounts]
A student can work in more than one project and a project can be done by more than one student.
A student can issue more than one book but a book is issued to only one student.
A subject is taught by more than one faculty and a faculty can teach more than one subject.
Participation Constraints
} It specifies the participation of an entity set in a relationship set.
} There are two types of participation constraints
Ê Total participation
Ê Partial participation
C1 L1
Each customer has
maximum one loan C2 L2
C3
Cardinality Ratio or (min, max) Notation for Relationship
} Cardinality Ratio: It defines minimum and maximum entity occurrences that participating in
a relationship.
} Each entity e in E participates in at least min and at most max relationship instances in R.
} Must have min£max, 0£ min £1£max, Default(no constraint): min=0, max=n.
(min, max)
(0, 1) (1, 2)
Assign
Employee Dept
to
e1 d1
e2 d2
e3
} Examples: e4
Ê A department has exactly one manager and an employee can manage at most one department.
§ Specify (1,1) for participation of DEPARTMENT in MANAGES
§ Specify (0,1) for participation of EMPLOYEE in MANAGES
Ê An employee can work for exactly one department but a department can have any number of employees.
§ Specify (1,1) for participation of EMPLOYEE in WORKS_FOR
§ Specify (1,n) for participation of DEPARTMENT in WORKS_FOR
Example: (min, max) notation for relationship
} Read the min, max numbers next to the entity type and looking away from the entity type
Note: If minimum cardinality is 0 then it is partial participation. If minimum cardinality is 1 then total participation.
Ramez Elmasri and Shamkant B. Navathe. 1989. Fundamentals of database systems. Benjamin-Cummings Publishing Co., Inc., USA.
Exercises:
} Interpret the following sample of E-R diagram and explain the relationship in terms of
participation.
Note: If minimum cardinality is 0 then it is partial participation. If minimum cardinality is 1 then total participation.
Ramez Elmasri and Shamkant B. Navathe. 1989. Fundamentals of database systems. Benjamin-Cummings Publishing Co., Inc., USA.
Keys : Super Key and Candidate Key
} Key or Super Key: An attribute or collection of attributes whose value uniquely identify an
entity in the entity set.
Ê Example: rollno, empid.
} Note: A key may have more than one attribute and an entity set may have more than one
key.
Name Roll No. Branch
} Student Name and Roll is a super key.
Ajay 101 ENC
Tanya 102 ENC
} Candidate Key: Super key whose proper subset cannot be a super key. Rohan 104 CSE
Ê Example: {Roll No.}, {Name, Branch} Ajay 106 CSE
Jatin 108 EC
} Primary Key: Any one candidate key which is selected for
Super Key
manipulating the data base.
Candidate Key
Primary Key
Weak Entity Set
An entity set that does not have a primary key is called weak entity set.
Payment-date
Saving_Account Current_Account
Sub Class
Generalization v/s Specialization
Generalization Specialization
It extracts the common features of multiple It splits an entity to form multiple new entities
entities to form a new entity. that inherit some feature of the splitting entity.
Name Address Name Address
SPI Salary
Person Person
Name Name
ISA ISA
Address Address
Bottom-up approach
Name Address
PID City
Person
ISA
ISA
Constraints
Disjoint Participation
Disjoint
Batsman Bowler ISA
(Sub class) (Sub class)
Full-time Part-time
(Sub class) (Sub class)
All the players are associated with only one sub class either (Batsman or Bowler).
Non-disjoint (Overlapping) Constraint
It specifies that an entity of a super class can belong to more than one lower-level entity set
(sub class).
Specified by ‘o’ or by writing overlapping near to the ISA triangle. Employee
Cricketer (Super class)
(Super class)
Non-disjoint
Batsman Bowler ISA
(Sub class) (Sub class)
Faculty Head
(Sub class) (Sub class)
One player (Yuvraj singh) is associated with more than one sub class.
Constraints on Specialization and Generalization
Constraints
Disjoint Participation
Professor Head
(Sub class) (Sub class)
All the players are associated with minimum one sub class either (Batsman or Bowler).
Partial (Optional) Participation
Partial participation specifies that every entity in the super class does not belong to any of the
subclass of specialization.
Specified by a single line in E-R diagram. Employee
Cricketer (Super class)
(Super class)
Professor Head
(Sub class) (Sub class)
Aggregation represents relationship between a whole object and its component. Using
aggregation we can express relationship among relationships. Aggregation shows ‘has-a’ or ‘is-
part-of’ relationship between entities where one represents the ‘whole’ and other ‘part’.
Limitation of E-R diagram
In E-R model we cannot express relationships between two relationships.
Customer
Company
Borrow Borrow
Loan Loan
MRID
PatID Name HosID Name
Indoor Outdoor
Doctor
RoomNo
IPDID OPDID DrID Dr Name
Charge
Summery of Symbols used in E-R diagram
Disjoint
E R E ISA ISA
One to One Total Disjoint
Specialization/ Specialization/
E R E Generalization Generalization
One to Many
E R E Overlapping
Primary Key
Student Project
EnrollNo Name Branch Sem ProjectID Title EnrollNo
190540107001 Raju CE 3 101 Bank 190540107001
190540107002 Mitesh CE 3 102 College 190540107002
190540107003 Nilesh CE 3 103 School 190540107003
190540107004 Meet CE 3 104 Hospital 190540107001
Student
RollNo Name Branch SPI
101 Raju CE 8
102 Mitesh ME 9
103 Nilesh CI 9
104 Meet CE 9
Student
RollNo Name Branch SPI
101 Raju CE 8
102 Mitesh ME 9
103 Nilesh CI 9
104 Meet CE 9
Student
RollNo Name Branch SPI
101 Raju CE 8
102 Mitesh ME 9
103 Nilesh CI 9
104 Meet CE 9
Employee
} Write down the relational algebra for the employee table.
Ê Display the detail of all employee. EmpID Name Dept Salary
Ê Display the detail of employee whose Salary more than 10000. 101 Nilesh Sales 10000
Ê Display the detail of employee belongs to “HR” Dept having Salary more 102 Mayur HR 25000
than 20000.
103 Hardik HR 15000
Ê Display the detail of employee belongs to either “HR” or “Admin” Dept.
Ê Display the detail of employee whose Salary between 10000 and 25000 104 Ajay Admin 20000
and belongs to “HR” Dept.
Student Output
RollNo Name Branch SPI RollNo Name Branch
101 Raju CE 8 101 Raju CE
102 Mitesh ME 9 102 Mitesh ME
103 Nilesh CI 9 103 Nilesh CI
104 Meet CE 9 104 Meet CE
Employee
} Write down the relational algebra for the employee table.
Ê Display EmpID with Name of all employee. EmpID Name Dept Salary
Ê Display Name and Salary of all employee. 101 Nilesh Sales 10000
Ê Display the Name of all employee. 102 Mayur HR 25000
Ê Display the Name of all departments. 103 Hardik HR 15000
104 Ajay Admin 20000
Student
RollNo Name Branch SPI
101 Raju CE 8
102 Mitesh ME 9
103 Nilesh CI 9
104 Meet CE 7
Student
RollNo Name Branch SPI
101 Raju CE 8
102 Mitesh ME 9
103 Nilesh CI 9
104 Meet CE 7
Step-1 σBranch=‘CE’ Λ SPI>7 (Student) Answer ∏ Name, Branch, SPI (σBranch=‘CE’ Λ SPI>7 (Student))
Output-1 Output-2
RollNo Name Branch SPI Name Branch SPI
101 Raju CE 8 Raju CE 8
Student
RollNo Name Branch SPI
101 Raju CE 8
102 Mitesh ME 9
103 Nilesh CI 9
104 Meet CE 7
Step-1 σBranch=‘ME’ V Branch=‘CI’ (Student) Answer ∏ Name, Branch (σBranch=‘ME’ V Branch=‘CI’ (Student))
Output-1 Output-2
RollNo Name Branch SPI Name Branch
102 Mitesh ME 9 Mitesh ME
103 Nilesh CI 9 Nilesh CI
} Write down the relational algebra for the employee table. Employee
Ê Display the Name of employee belong to “HR” Dept and having salary EmpID Name Dept Salary
more than 20000. 101 Nilesh Sales 10000
Ê Display the Name of all “Admin” and “HR” Dept’s employee.
102 Mayur HR 25000
Ê List the Name of employee with their Salary who belongs to “HR” or
“Admin” Dept having salary more than 15000. 103 Hardik HR 15000
Ê Display the Name of employee along with their Dept name whose 104 Ajay Admin 20000
salary between 15000 and 30000.
Example Perform Cross Product between Student and Result. Answer (Student) X (Result)
Example Display the name of students with their project name whose guide is “A. J. Shah”.
Student Result
RollNo Name Branch RollNo SPI BL
101 Raj CE 101 8 1
102 Meet ME 103 9 0
Output
RollNo Name SPI
101 Raj 8
102 Meet NULL
Student Result
RollNo Name Branch RollNo SPI BL
101 Raj CE 101 8 1
102 Meet ME 103 9 0
Output
RollNo Name SPI
101 Raj 8
103 NULL 9
Student Result
RollNo Name Branch RollNo SPI BL
101 Raj CE 101 8 1
102 Meet ME 103 9 0
Conditions Set operators will take two or more queries as input, which must be union-compatible.
Example Perform Intersection between Customer and Employee. Answer (Customer) ∩ (Employee)
Customer Employee Output
Name Name Name
Raju Meet Meet
Suresh Suresh Suresh
Meet Manoj
Exercise Is there any difference in the output if we swap the tables in Intersection. (Employee) ∩ (Customer).
Prof. Firoz A Sherasiya #3130703 (DBMS) w Unit 3 – Relational Query Languages 51
Minus/ Set difference Operator
} Symbol: −
} Notation: Relation-1 (R1) − Relation-2 (R2) OR Algebra-1 − Algebra-2
} Operation:
Ê It displays all the tuples/records belonging to the first relation (left relation) but not in the second relation
(right relation).
Example Perform Set difference between Customer and Employee. Answer (Customer) − (Employee)
Customer Employee Output
Name Name Name
Raju Meet Raju
Suresh Suresh
Meet Manoj
Exercise Is there any difference in the output if we swap the tables in Set difference. (Employee) − (Customer).
Prof. Firoz A Sherasiya #3130703 (DBMS) w Unit 3 – Relational Query Languages 52
Union Operators Example
Example Display Name of person who are either employee or customer.
Customer Employee
ID Name Balance ID Name Dept Salary
1 Raju 10000 2 Suresh CE 8000
2 Suresh 20000 3 Manoj ME 9000
Customer Employee
ID Name Balance ID Name Dept Salary
1 Raju 10000 2 Suresh CE 8000
2 Suresh 20000 3 Manoj ME 9000
Customer Employee
ID Name Balance ID Name Dept Salary
1 Raju 10000 2 Suresh CE 8000
2 Suresh 20000 3 Manoj ME 9000
Raj DS DS Suresh
Meet DS DF
Meet DF
Rohit DBMS
Rohit DS
Rohit DF
Suresh DBMS
Suresh DF
Suresh DS
Student Project
RNo Name Technology TID Technology
101 Raj .NET 1 .NET
101 Raj PHP 2 PHP
102 Meet .NET 3 Android
102 Meet PHP 4 iPhone
102 Meet iPhone
Answer ∏ Name, Technology (Student) ÷ ∏ Technology (Project)
102 Meet Android
103 Rohit Android Output
Person Student
RNo Name CPI RollNo StudentName SPI
101 Raj 8 101 Raj 8
102 Meet 9 102 Meet 9
103 Jay 7 103 Jay 7
Algebra ρPerson (RollNo, StudentName) (∏ RNo, Name (Student)) Algebra ρStudentName / Name (Student)
Person Student
RollNo StudentName Rno StudentName CPI
101 Raj 101 Raj 8
102 Meet 102 Meet 9
103 Jay 103 Jay 7
Student
Step-3 ∏ A.CPI (σA.CPI<B.CPI (ρA (Student) X ρB (Student)))
Rno Name CPI
101 Raj 8 Output-3
A.CPI
102 Meet 9
8
103 Jay 7
7
Output-2
A.Rno A.Name A.CPI B.Rno B.Name B.CPI
101 Raj 8 102 Meet 9
103 Jay 7 101 Raj 8
103 Jay 7 102 Meet 9
Student
Step-3 ∏ A.CPI (σA.CPI<B.CPI (ρA (Student) X ρB (Student)))
Rno Name CPI
101 Raj 8 Output-3
A.CPI
102 Meet 9
8
103 Jay 7
7
Consider the following relational database schema consisting of the four relation schemas:
Question 2. Get the details about all flights from Chennai to New Delhi.
σsrc=”Chennai” ∧ dest=”N ewDelhi” (f light)
Question 3. Find only the flight numbers for passenger with pid 123 for flights to Chennai before
06/11/2020.
πf id [(σpid=123 (booking)) ▷◁ (σdest=”Chennai” ∧ f date<06/11/2020 (f light))]
Question 4. Find the passenger names for passengers who have bookings on at least one flight.
πpname (passenger ▷◁ booking)
Question 5. Find the passenger names of those who do not have any bookings in any flights.
πpname [(πpid (passenger) − πpid (booking)) ▷◁ P assenger]
Question 6. Find the agency names for agencies that located in the same city as passenger with passenger
id 123.
πaname (agency ▷◁pcity=acity (σpid=123 (passenger)))
Question 7. Get the details of flights that are scheduled on both dates 01/12/2020 and 02/12/2020 at
16:00 hours.
[σf date=01/12/2020 ∧ time=16:00 (f light)] ∩ [sigmaf date=02/12/2020 ∧ time=16:00 (f light)]
Question 8. Get the details of flights that are scheduled on either of the dates 01/12/2020 or 02/12/2020
or both at 16:00 hours.
[σf date=01/12/2020 ∧ time=16:00 (f light)] U [sigmaf date=02/12/2020 ∧ time=16:00 (f light)]
1
2
Question 9. Find the agency names for agencies who do not have any bookings for passenger with id
123.
πaname [agency ▷◁ [πaid (agency) − πaid (σpid=123 (booking))]
Question 10. Find the details of all male passengers who are associated with Jet agency.
πpid,pname,pgender,pcity [σpgender=”M ale”∧aname=”Jet” (passenger ▷◁ booking ▷◁ agency)]