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

PRACTICAL FILE

OF
“INFORMATION SYSTEM MANAGEMENT LAB”
B.B.A. (G) 212
Submitted in partial fulfillment of the
requirement Of
B.B.A. (G)
Batch 2021-2022

SUBMITTED TO Ms. Indu Associate Professor (Mgmt.)

SUBMITTED BY Sidak Preet Singh

CHANDERPRABHU JAIN COLLEGE OF HIGHER STUDIES &


SCHOOL OF LAW (Approved by Govt. of NCT of Delhi Affiliated to
Guru Govind Singh Indraprastha University,Delhi)
1
INDEX
S.NO TOPIC Page No. SIGN

1. Give Introduction to Database. 3-10

2. Make ER diagram of Hospital 11-15


Management System.

3. Make ER diagram of Examination System. 15-18

4. Create Student Table. 18-19

5. Create Emp_info Table. 20-22

6. Display the salary of all employees 23-24


from Emp_info table.

7. Display the different departments in 25-26


the company from Emp_info table.

8. Display total number of departments in 27-29


the company from emp_info table.

9. Display the name of employees whose 29-31


name starts with ‘a’.

10. Display the name of those employees 32-34


whose 2nd alphabet is ‘a’

11. Display id & name of those employees 34-36


who lives in Delhi.

12. Display id & name of those employees 36-38


who lives in Delhi/Mumbai.

13. Display name & max salary in each 38-41


department of company.
14. Add Phone No. Column in emp_info table. 41-43

15. Update the city of Mr. John from Jaipur 43-45


to Chennai.

2
Q1. INTRODUCTION TO DATABASE?
DBMS stands for DataBase Management System. Its file extension is (.dbf). Database is a
collection of data and management system which is a set of programs to store and retrieve
those data. It is general purpose software that enables users to define, create and maintain a
database. It facilitates the processes of defining, constructing, manipulating databases for
various applications. It also helps in sharing, protection and maintenance of databases.
Database stores information whereas DBMS is a system to manage database.

A database management system (DBMS) is a collection of programs that manages the


database structure and controls access to the data stored in the database. DBMS is general
purpose software with a collection of programs that enable usersto define, create and maintain
database. It facilitate the process of defining, constructing, manipulating databases, it also
helps in sharing, protection and maintenance of database.
The DBMS serves as the intermediary between the user and the database. The database
structure itself is stored as a collection of files. So, we can access the data in those files
through the DBMS.
The DBMS receives all application requests and translates them into the complex operations
required to fulfil those requests. The DBMS hides much of the database’s internal complexity
from the application programs and users.
A database system is just a computerized record-keeping system. The database is regarded as
a kind of repository or container for a collection of computerized data files where users can
perform a variety of operations.

A database is an organized collection of structured information, or data, typically stored


electronically in a computer system. A database is usually controlled by a database
management system (DBMS). Together, the data and the DBMS, along with the applications
that are associated with them, are referred to as a database system, often shortened to just
database.

It is any collection of data that is stored as a file or a set of files or magnetic disc or some
secondary devices. The information in the file may be broken down into records. Each record
consists of one or more fields. We perform different types of command in a database to
retrieve or create report on particular data.
It is a collection of interrelated data. These can be stored in the form of tables. A database can
be of any size and varying complexity. A database may be generated and manipulated
manually or it may be computerized.

A Dictionary, a phone book, a collection of recipes and a TV guide are examples of non
computerized databases. The examples of computerized databases includes customer files,
employee rosters, books catalog, equipment inventories and sales transactions. Typically, a
database manager provides users the capabilities of controlling read/write access, specifying
report generation, and analyzing usage.

3
⮚ DATA BASE MANAGEMENT SYSTEM
4
⮚ NEED FOR DBMS

Database systems are basically developed for large amount of data. A database management
system (DBMS) can help address the employee count scenario and a range of even more
complex situations related to cost, order status or inventory management by presenting the same
data to everyone in the business at the same time. A DBMS also eliminates the frustrating hunt
for the right version of the right spreadsheet on a vast and disorganized network drive. When
dealing with huge amount of data, there are two things that require optimization:
∙ Storage of data
∙ Retreival of data

Storage: The data is stored in such a way that it acquires less space as the redundant data
(duplicate data) has been removed before storage.
Retreival: Along with storing the data in an optimized and systematic manner, it is also
important that retrieve the data quickly when needed.
A Data Base Management System is a system software for easy, efficient and reliable data
processing and management. It can be used for:

∙ Creation of a database.
∙ Retrieval of information from the database.
∙ Updating the database.
∙ Managing a database.

Needs are:

A database system is a central depository in an organisation’s information system and is essential


for supporting the organization’s functions, maintaining the data for these functions and helping
users interpret the data in decision making.

∙ As businesses expand, more sophisticated tools are needed to manage data. Tools that serve
start-ups well are overwhelmed by the demands faced by larger businesses. ∙ A database
management system (DBMS) is a powerful tool used to store data, secure it, protect it and
make it quickly available to people who need it.

5
USES OF DBMS:

⮚ Simplified Data Sharing:


A DBMS allows users to easily share the data by following the correct authorization protocols. It
provides operators access to well-managed data. As a result, they can rapidly respond to variations in the
environment.
By using a DBMS, you can yield speedy responses to impromptu queries as the data is properly managed
and up-to-date. In case of any ad hoc query, the database management software returns a response
(known as the query result set) to the application.
⮚ Enhanced Data Safety:
The threats of data security breaches become more pronounced when several users access the database. A
database management software offers better implementation of data confidentiality and safety guidelines
through controlled user access.
⮚ Improved Data Integration:
A DBMS stimulates an integrated view of the company’s data. The company can quickly see how
activities in one division of the organization influence other divisions.
⮚ Better Decision-Making:
A database management system provides access to well-managed data, making it possible for users to
make accurate and timely decisions. It offers a streamlined framework to enable data quality initiatives,
improving data management procedures and yielding better-quality information.
⮚ Improved Efficiency:
Streamlined data access, along with the tools that convert data into valuable information, enable
operators to make swift, knowledgeable decisions. This improves database performance and efficiency.

6
CHARACTERISTICS OF DBMS:
1. Real World Entity
DBMS these days is very realistic and real-world entities are used to design its architecture. Also
behavior and attributes are used by DBMS. To simplify it we can take an example of an organization
database where employee is an entity and his employee id is an attribute.
2. Self-Describing Nature
Before DBMS, traditional file management system was used for storing information and data. There was
no concept of definition in traditional file management system like we have in DBMS. A DBMS should
be of Self- Describing nature as it not only contains the database itself but also the metadata. A metadata
(data about data) defines and describes not only the extent, type, structure and format of all data but also
relationship between data. This data represent itself that what actions should be taken on it.
3. Support ACID Properties
Any DBMS is able to support ACID (Accuracy, Completeness, Isolation, and Durability) properties. It is
made sure in every DBMS that the real purpose of data should not be lost while performing transactions

7
like delete, insert and update. Let us take an example; if an employee name is updated then it should
make sure that there is no duplicate data and no mismatch of employee information.
4. Concurrent Use of Database
There are many chances that many users will be accessing the data at the same time. They may require
altering the database system concurrently. At that time, DBMS supports them to concurrently use
database without any problem. With the help of concurrency, economy of the system can be increased.
For Example, employees of railway reservation system can book and access tickets for passengers
concurrently. Every employee can see on his own interface that how many seats are available or bogie is
fully booked.

5. Insulation Between Data and Program

Program-data independence provides a big relief to database users. In traditional file management
system, structure of data files was defined in the application programs so user had to change all the
programs that are using that particular data file.

But in DBMS, structure of data files is not stored in the program but it is stored in system catalogue.
With the help of this, internal improvement of data efficiency or any changes in the data do not have any
effect on application software.

6. Transactions

Transactions are bunch of actions that are done to bring database from one consistent state to new
consistent state. Traditional file-based system did not have this feature. Transaction is always atomic that
means it can never be further divided. It can only be completed or uncompleted.

For example, A person wants to credit money from his account to another person’s account. Then
transaction will be complete if he sends money and other guy receives his money. Anything other than
this can lead to an inconsistent transaction.

8
PROPERTIES OF DBMS:
⮚ ACID Properties
A transaction is a very small unit of a program and it may contain several low level tasks. A transaction
in a database system must maintain Atomicity, Consistency, Isolation, and Durability − commonly
known as ACID properties − in order to ensure accuracy, completeness, and data integrity.
Atomicity
This property states that a transaction must be treated as an atomic unit, that is, either all of its operations
are executed or none. There must be no state in a database where a transaction is left partially completed.
States should be defined either before the execution of the transaction or after the execution/ failure of the
transaction.
Consistency
The database must remain in a consistent state after any transaction. No transaction should have any
adverse effect on the data residing in the database. If the database was in a consistent state before the
execution of a transaction, it must remain consistent after the execution of the transaction as well.
Isolation
In a database system where more than one transaction are being executed simultaneously and in parallel,
the property of isolation states that all the transactions will be carried out and executed as if it is the only
transaction in the system. No transaction will affect the existence of any other transaction.
Durability
The database should be durable enough to hold all its latest updates even if the system fails or restarts. If
a transaction updates a chunk of data in a database and commits, then the database will hold the modified
data. If a transaction commits but the system fails before the data could be written on to the disk, then
that data will be updated once the system springs back into action.

9
⮚ Advantage of Database Management System (DBMS):
∙ Better Data Transferring:
Database management creates a place where users have an advantage of more and better managed
data. Thus making it possible for end-users to have a quick look and to respond fast to any
changes made in their environment.

∙ Better Data Security:


As number of users increases data transferring or data sharing rate also increases thus increasing
the risk of data security. It is widely used in corporation world where companies invest money,
time and effort in large amount to ensure data is secure and is used properly. A Database
Management System (DBMS) provide a better platform for data privacy and security policies
thus, helping companies to improve Data Security

∙ Better data integration:


Due to Database Management System we have an access to well managed and synchronized form
of data thus it makes data handling very easy and gives integrated view of how a particular
organization is working and also helps to keep a track on how one segment of the company
affects other segment.

∙ Minimized Data Inconsistency:


Data inconsistency occurs between files when different versions of the same data appear in
different places.
For Example, data inconsistency occurs when a student name is saved as “John Wayne” on a
main computer of school but on teacher registered system same student name is “William J.
Wayne”, or when the price of a product is $86.95 in local system of company and its National
sales office system shows the same product price as $84.95.
So if a database is properly designed then Data inconsistency can be greatly reduced hence
minimizing data inconsistency.

∙ Faster data Access:


The Data base management system (DBMS) helps to produce quick answers to database queries
thus making data accessing faster and more accurate. For example, to read or update the data. For
example, end users, when dealing with large amounts of sale data, will have enhanced access to
the data, enabling faster sales cycle.

10
Q2. Make ER Diagram of Hospital Management System
⮚ SYSTEM ENTITY RELATIONSHIP MODEL

An Entity–relationship model (ER model) describes the structure of a database with the
help of a diagram, which is known as Entity Relationship Diagram (ER Diagram). An ER
model is a design or blueprint of a database that can later be implemented as a database. The
main components of E-R model are: entity set and relationship set. An entity–relationship
model (or ER model) describes interrelated things of interest in a specific domain of
knowledge. A
basic ER model is composed of entity types(which classify the things of interest) and
specifies relationships that can exist between entities (instances of those entity types).

It is a high-level data model. This model is used to define the data elements and relationship
for a specified system. It develops a conceptual design for the database. It also develops a
very simple and easy to design view of data.

⮚ Entity Relationship Diagram (ER Diagram)

An ER diagram shows the relationship among entity sets. An entity set is a group of similar
entities and these entities can have attributes. In terms of DBMS, an entity is a table or
attribute of a table in database,so by showing relationship among tables and their attributes,
ER diagram shows the complete logical structure of a database. ER diagram (Entity
relationship diagram) displays the relationships of entity set stored in a database. In other
words, we can say thatER diagrams help you to explain the logical structure of databases.

ER diagrams often use symbols to represent three different types of information. Boxes are
commonly used to represent entities. Diamonds are normally used to represent relationships
and ovals are used to represent attributes of and entity.

ER Diagram is a pictorial representation of a system. We have data objects, entities and


relationship between them.

11
⮚ Components of a ER Diagram

An ER diagram has three main components:


1.Entity
2.Atribue
3. Relationship

1. Entity

Entity can be described as the atomic real world item. It may be person, place, object, event
etc. An entity is an object or component of data. For example. If all the students studying in a
college such group is called entity set. An entity is represented as rectangle in an ER
diagram.

Entity

2. Attribute
An attribute describes the property of an entity. An entity is described using a set of
attributes. An attribute is represented as Oval in an ER diagram.

12
3. Relationships
Association among two or more entities is called relationship. A relationship is defined
as the bond attachment between two or more entities normally a verb in a sentence
signifies a relationship. The graphical representation of a relationship is a Diamond.

Example an association between customer of a bank.

13
ER DIAGRAM OF HOSPITAL MANAGEMENT SYSTEM:
Step 1: E-R Diagram

This ER Diagram represents the model of Hospital Management System Entity. It shows all
the visual instrument of database tables and the relations between patient, employee, record,
doctor and room etc. It used structure data and to define the relationships between structured
data groups of Hospital Management System functionalities. The entities and attributes are:-

14
∙ Patients Entity: Attributes of patients are p_id, p_name, p_address, p_gender
and p_contact_no.
∙ Room Entity: Attributes are room_type, room_id and room_period.
∙ Employee Entity: Attributes of employees are e_id, e_salary, e_address,
e_gender, e_name and e_contact_no.
∙ Medicine Entity: Attributes of medicines are med_price, med_quantity and med_code.

Q3. Make ER diagram of HOTEL System?

SYSTEM ENTITY RELATIONSHIP MODEL

An Entity–relationship model (ER model) describes the structure of a database with the
help of a diagram, which is known as Entity Relationship Diagram (ER Diagram). An ER
model is a design or blueprint of a database that can later be implemented as a database. The
main components of E-R model are: entity set and relationship set. An entity–relationship
model (or ER model) describes interrelated things of interest in a specific domain of
knowledge. A
basic ER model is composed of entity types(which classify the things of interest) and
specifies relationships that can exist between entities (instances of those entity types).

It is a high-level data model. This model is used to define the data elements and relationship
for a specified system. It develops a conceptual design for the database. It also develops a
very simple and easy to design view of data.

⮚ Entity Relationship Diagram (ER Diagram)

An ER diagram shows the relationship among entity sets. An entity set is a group of similar
entities and these entities can have attributes. In terms of DBMS, an entity is a table or
attribute of a table in database,so by showing relationship among tables and their attributes,
ER diagram shows the complete logical structure of a database. ER diagram (Entity
relationship diagram)

15
displays the relationships of entity set stored in a database. In other words, we can say thatER
diagrams help you to explain the logical structure of databases.
ER diagrams often use symbols to represent three different types of information. Boxes are
commonly used to represent entities. Diamonds are normally used to represent relationships
and ovals are used to represent attributes of and entity.

ER Diagram is a pictorial representation of a system. We have data objects, entities and


relationship between them.

Components of a ER Diagram
An ER diagram has three main components:
1.Entity
2.Attribute
3. Relationship

1. Entity
Entity can be described as the atomic real world item. It may be person, place, object, event etc. An
entity is an object or component of data. For example. If all the students studying in a college such
group is called entity set. An entity is represented as rectangle in an ER diagram.

Entity

2. Attribute
An attribute describes the property of an entity. An entity is described using a set of
attributes. An attribute is represented as Oval in an ER diagram.

3. Relationships:-
Association among two or more entities is called relationship. A relationship is defined as
the bond attachment between two or more entities normally a verb in a sentence signifies a
relationship. The graphical representation of a relationship is a Diamond.

16
ER DIAGRAM OF HOTEL MANAGEMENT SYSTEM:


Hotel entity : attributes of hotel are hotel_id, hotel_name,hotel_rent.
17
∙ Room Entity: Attributes of room_type, room_id and room_period.

∙ Services entity : Attributes of services are service_id, service_name.

∙ Payment entity : Attributes of Payment are Payment_id, Payment_date.

Q4. Create Student Table?


Ans 4 : Creating a basic table involves naming the table and defining its columns and each
column’s data type.

Syntax: create table table_name(column1 data type primary key, column2 data type, column3
data type,.columnN data type);

QUERY:

For creating student table the following command is: create table students(id
integar(5),name varchar(20), age integer(3), class varchar(5), address varchar(20)

OUTPUT:

You can verify if your table has been created successfully by looking at the message
displayed by the SQL server, otherwise you can use DESC command as mentioned
above.

18
Primary key is a field in a table which uniquely identifies each row/record in database
table. It should contain any NULL values.

For inserting values:


Insert into statement is used to insert new records in table.

QUERY:
For inserting values in student table the following command is

insert into students1 values(1,'raghav',21,11,'narela');

insert into students1 values(2,'rudransh',18,11,'rohini');

insert into students1 values(3,'binod',22,12,'alipur');

insert into students1 values(4,'steve',100,12,'new york');

insert into students1 values(5,'ava adam',25,12,'america');

OUTPUT:

19
Q5. Create an emp_info and insert values in it.
Ans 5: Creating a basic table involves naming the table and defining its columns and
each column’s data type.

Syntax: create table table_name(column1 data type primary key, column2 data
type, column3 data type,. columnN data type);
QUERY:
For creating student table the following command is: create table emp_info( emp_id
integer(20) primary key, emp_name varchar(20)not null, emp_city varchar(20)not null,
emp_salary number(30)not null, emp_dept varchar(20) not null);

OUTPUT:

You can verify if your table has been created successfully by looking at the message
displayed by the SQL server,

20
Primary key is a field in a table which uniquely identifies each row/record in
database table. It should contain any NULL values.

For inserting values:

Insert into statement is used to insert new records in table.

Syntax: Insert Into table_name Values(value1, value2, value3,. )

QUERY:

For inserting values in emp_info table the following command is:


Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',35000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(5,'Karina','Chennai',60000,'Sales');

21
OUTPUT:
22

Q6. Display the salary of all employees from Emp_info table.


Ans 6: First we have to display the table where all the records are entered for the following
command is: - select * from Emp_info;

The table will execute with the fields you have entered.
QUERY: Select emp_salary from emp_info;

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',35000,'Purchase');

23
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(5,'Karina','Chennai',60000,'Sales');

OUTPUT:
24
Q7. Display the different departments in the company from
Emp_info table.
Ans 7 :First we have to display the table where all the records are entered for the
following command is: - select * from Emp_info;

The table will execute with the fields you have entered.
QUERY: Select emp_dept from emp_info;
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

25
values

(3,'Alok','Bangalore',35000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values


(5,'Karina','Chennai',60000,'Sales');

OUTPUT:

26
Q8. Display total number of departments in the company
from emp_info table.
Ans 8: First we have to display the table where all the records are entered for the
following command is: - select * from Emp_info;

The table will execute with the fields you have entered.
Here we will use an aggregate function: - COUNT() It returns the number of rows
in a table. It allows you to count all rows or only rows that match a specified
condition.

Syntax: Select Count(column_name) from


table_name;

QUERY: Select Count(emp_dept) from


emp_info;

27
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values
(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',35000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(5,'Karina','Chennai',60000,'Sales');

28
OUTPUT:
Q9. Display the name of employees whose name starts with ‘A’.
Ans 9: Under this Like operator is used to search for a specified pattern in a column.
There are 2 wildcards often used in conjunction with the Like operator: %, _

%: Represents zero or more characters.

_: Represents a single character.

We have also used Where clause in this command. Where clause allows you to
specify a search condition for the rows returned by a query. Where clause in select
statement is to filter rows from the result set.

29
Syntax: Select column1,coulmn2,from table_name where condition;

QUERY: Select emp_name from emp_info where emp_name like ‘A%’;

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',35000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

30
values
(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(5,'Karina','Chennai',60000,'Sales');

OUTPUT:

31

Q10. Display the name of those employees whose 2nd alphabet is ‘a’

ANS 10. Under this Like operator is used to search for a specified pattern in a
column. There are 2 wildcards often used in conjunction with the Like operator:
%, _

%: Represents zero or more characters.

_: Represents a single character.


We have also used Where clause in this command. Where clause allows you to
specify a search condition for the rows returned by a query. Where clause in select
statement is to filter rows from the result set.

Syntax: Select column1,column2,..from table_name where condition;

QUERY: Select emp_name from emp_info where emp_name like ‘_a%’;


Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',90000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

32
(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(5,'Karina','Chennai',60000,'Sales');
OUTPUT:

33
Here the output will show the name of only those employees whose 2nd alphabet is
‘A’. Where we have used both wildcards: %, _

Q11. Display id & name of those employees who lives in Delhi.


ANS 11. Under this Where clause allows you to specify a search condition for the
rows returned by a query. Where clause in select statement is to filter rows from the
result set.
QUERY: Select emp_id, emp_name from emp_info where emp_city=”Delhi”;
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',90000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(5,'Karina','Chennai',60000,'Sales');

34
Output:

35
It will display the id and name of those employees who live in Delhi only.

Q12. Display id & name of those employees who lives in


Delhi/Mumbai.
ANS 12. Under this Where clause allows you to specify a search condition for the
rows returned by a query. Where clause in select statement is to filter rows from the
result set. We have also used Or operator which displays a record if any of the
conditions separated by Or is True.

Syntax: Select column1, column2,.. From table_name where condition1 or


condition2 or condition3. ;

QUERY: Select emp_id, emp_name from emp_info where emp_city=”Delhi” or


emp_city=“Mumbai”;
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',90000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(4,'Neena','Jaipur',72000,'Marketing');

36
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(5,'Karina','Chennai',60000,'Sales');
37

Output:

It will display the id and name of those employees who lives in Delhi or Mumbai.
Q13. Display name & max salary in each department of company.
ANS 13. Under this Where clause allows you to specify a search condition for the rows
returned by a query. Where clause in select statement is to filter rows from the result
set.

Apart from that MAX() function is also used. It is an aggregate function that returns

the maximum value from an expression.

Syntax: MAX( DISTINCT expression)

QUERY: Select emp_name, emp_dept from emp_info where


emp_salary=(select max(emp_salary) from emp_info);

38
In this query there are 2 statements made together where we have used where clause
and max function. This is an example of Nested querywhere there are 2 queries:
Inner and Outer.

Outer Query.

Select emp_name, emp_dept fromemp_info where emp_salary=(select


max(emp_salary) from emp_info);

Inner Query.

Now, inner query will be executed first and will return the output i.e. it will display
the maximum salary from emp_info table which is 90000. And then it will be
compared with the outer query which is: select the emp_name and emp_dept.
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(3,'Alok','Bangalore',90000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

39
(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(5,'Karina','Chennai',60000,'Sales');
Output:

40
Q14. Add Phone No. Column in emp_info table.
ANS 14. Here ALTER command is used. It helps to modify an existing database and
table. The ALTER statement is used to “ADD”, “DROP” and “MODIFY” the existing
table.

ADD Column: To add column in a table.

Syntax (to add a column): ALTER table table_name ADD column_name, datatype;

QUERY: Alter table emp_info add emp_phoneno number(10);


Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

41
values
(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(3,'Alok','Bangalore',90000,'Purchase');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(5,'Karina','Chennai',60000,'Sales');

42
Output:
Q15. Update the city of Mr. John from Jaipur to Chennai.
ANS 15. Here UPDATE statement is used. It helps to modify existing data in a table.
Update statement change values in one or more columns of a single row or multiple
rows.
Syntax: UPDATE table_name set column1= value where some_column= some_value.
QUERY: Update emp_info set emp_city= “Chennai” where emp_name= “alok”; Insert
into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(1,'Raghav','Delhi',40000,'Human Resources');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

values

(2,'Veenu','Mumbai',50000,'Finance');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept)

43
values

(3,'Alok','Bangalore',90000,'Purchase');
Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(4,'Neena','Jaipur',72000,'Marketing');

Insert into emp_info(emp_id,emp_name,emp_city,emp_salary,emp_dept) values

(5,'Karina','Chennai',60000,'Sales');

44
Output:
45

You might also like