Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

Database Management System (AY 2023-2024)

Practical - 1

Practical - 1. To study DDL-create and DML-insert commands.

(i) Create tables according to the following definition.

1. CREATE TABLE DEPOSIT (ACTNO VARCHAR2(5) ,CNAME


VARCHAR2(18) , BNAME VARCHAR2(18) , AMOUNT
NUMBER(8,2) ,ADATE DATE);
2. CREATE TABLE BRANCH(BNAME VARCHAR2(18),CITY
VARCHAR2(18));
3. CREATE TABLE CUSTOMERS(CNAME VARCHAR2(19) ,CITY
VARCHAR2(18));
4. CREATE TABLE BORROW(LOANNO VARCHAR2(5), CNAME
VARCHAR2(18), BNAME VARCHAR2(18), AMOUNT NUMBER (8,2));

Query :-
1. CREATE TABLE DEPOSIT ( 1ACTNO VARCHAR(5),
CNAME VARCHAR(18),
BNAME VARCHAR(18),
AMOUNT DECIMAL(8, 2),
ADATE DATE ) ;
2. CREATE TABLE BRANCH (
BNAME VARCHAR(18),
CITY VARCHAR(18) );
3. CREATE TABLE CUSTOMER (
CNAME VARCHAR(19),
CITY VARCHAR(18) );
4. CREATE TABLE BORROW (
LOANNO VARCHAR(5),
CNAME VARCHAR(18),
BNAME VARCHAR(18),
AMOUNT DECIMAL(8, 2) );

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

(ii) Insert the data as shown below.

DEPOSIT

ACTNO CNAME BNAME AMOUNT ADATE

100 ANIL VRCE 1000.00 1-MAR-95

101 SUNIL AJNI 5000.00 4-JAN-96

102 MEHUL KAROLBAGH 3500.00 17-NOV-95

104 MADHURI CHANDI 1200.00 17-DEC-95

105 PRMOD M.G.ROAD 3000.00 27-MAR-96

106 SANDIP ANDHERI 2000.00 31-MAR-96

107 SHIVANI VIRAR 1000.00 5-SEP-95

108 KRANTI NEHRU 5000.00 2-JUL-95


PLACE
109 MINU POWAI 7000.00 10-AUG-95

INSERT INTO DEPOSIT VALUES ('100', 'ANIL', 'VRCE', 1000.00, "95-03-01");


INSERT INTO DEPOSIT VALUES ('101', 'SUNIL', 'AJNI', 5000.00, "96-01-04");
INSERT INTO DEPOSIT VALUES ('102', 'MEHUL', 'KAROLBAGH', 3500.00,
"95-11-17");
INSERT INTO DEPOSIT VALUES ('104', 'MADHURI', 'CHANDI', 1200.00,"95-
12-17");
INSERT INTO DEPOSIT VALUES ('105', 'PRMOD', 'M.G.ROAD', 3000.00,"96-
03-27");
INSERT INTO DEPOSIT VALUES ('106', 'SANDIP', 'ANDHERI', 2000.00,"96-
03-31");
INSERT INTO DEPOSIT VALUES ('107', 'SHIVANI', 'VIRAR', 1000.00,"95-09-
05");
INSERT INTO DEPOSIT VALUES ('108', 'KRANTI', 'NEHRU PLACE', 5000.00,"95-
07-02");INSERT INTO DEPOSIT VALUES ('109', 'MINU', 'POWAI', 7000.00,"95-
08-10");

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

BRANCH

VRCE NAGPUR
AJNI NAGPUR
KAROLBAGH DELHI
CHANDI DELHI
DHARAMPETH NAGPUR
M.G.ROAD BANGLORE
ANDHERI BOMBAY
VIRAR BOMBAY
NEHRU PLACE DELHI
POWAI BOMBAY

INSERT INTO BRANCH VALUES (‘VRCE’, ‘NAGPUR’); INSERT INTO BRANCH


VALUES (‘AJNI’, ‘NAGPUR’); INSERT INTO BRANCH VALUES (‘KAROLBAGH’,
‘DELHI’); INSERT INTO BRANCH VALUES (‘CHANDI’, ‘DELHI’); INSERT INTO
BRANCH VALUES (‘DHARAMPETH’, ‘NAGPUR’); INSERT INTO BRANCH
VALUES (‘M.G.ROAD’, ‘BANGLORE’); INSERT INTO BRANCH VALUES
(‘ANDHERI’, ‘BOMBAY’); INSERT INTO BRANCH VALUES (‘VIRAR’, ‘BOMBAY’);
INSERT INTO BRANCH VALUES (‘NEHRU PLACE’, ‘DELHI’); INSERT INTO
BRANCH VALUES (‘POWAI’, ‘BOMBAY’); CUSTOMERS

ANIL CALCUTTA
SUNIL DELHI
MEHUL BARODA
MANDAR PATNA
MADHURI NAGPUR
PRAMOD NAGPUR
SANDIP SURAT
SHIVANI BOMBAY

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

KRANTI BOMBAY
NAREN BOMBAY

INSERT INTO CUSTOMERS VALUES (‘ANIL’, ‘CALCUTTA’); INSERT INTO


CUSTOMERS VALUES (‘SUNIL’, ‘DELHI’); INSERT INTO CUSTOMERS VALUES
(‘MEHUL’, ‘BARODA’); INSERT INTO CUSTOMERS VALUES (‘MANDAR’,
‘PATNA’); INSERT INTO CUSTOMERS VALUES (‘MADHURI’, ‘NAGPUR’);
INSERT INTO CUSTOMERS VALUES (‘PRAMOD’, ‘NAGPUR’); INSERT INTO
CUSTOMERS VALUES (‘SANDIP’, ‘SURAT’); INSERT INTO CUSTOMERS VALUES
(‘SHIVANI’, ‘BOMBAY’); INSERT INTO CUSTOMERS VALUES (‘KRANTI’,
‘BOMBAY’); INSERT INTO CUSTOMERS VALUES (‘NAREN’, ‘BOMBAY’);

BORROW
LOANN CNAME BNAME AMOUN
O T
201 ANIL VRCE 1000.00
206 MEHUL AJNI 5000.00
311 SUNIL DHARAMPET 3000.00
H
321 MADHUR ANDHERI 2000.00
I
375 PRMOD VIRAR 8000.00
481 KRANTI NEHRU 3000.00
PLACE
INSERT INTO BORROW VALUES (‘201’, ‘ANIL’, ‘VRCE’, 1000.00); INSERT INTO
BORROW VALUES (‘206’, ‘MEHUL’, ‘AJNI’, 5000.00); INSERT INTO BORROW
VALUES (‘311’, ‘SUNIL’, ‘DHARAMPETH’, 3000.00); INSERT INTO BORROW
VALUES (‘321’, ‘MADHURI’, ‘ANDHERI’, 2000.00); INSERT INTO BORROW
VALUES (‘375’, ‘PRMOD’, ‘VIRAR’, 8000.00); INSERT INTO BORROW VALUES
(‘481’, ‘KRANTI’, ‘NEHRU PLACE’, 3000.00);

(iii) From the above given tables perform the following queries:

(1) Describe deposit, branch.


Desc DEPOSIT ;
Desc BRANCH ;
(2) Describe borrow, customers.
Desc BORROW;
Desc CUSTOMER;

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

(3) List all data from table DEPOSIT. SELECT *


FROM DEPOSIT;
(4) List all data from table BORROW. SELECT *
FROM BORROW;
(5) List all data from table CUSTOMERS. SELECT
* FROM CUSTOMER;
(6) List all data from table BRANCH. SELECT *
FROM BRANCH;
(7) Give account no and amount of depositors.
SELECT ACTNO, AMOUNT FROM DEPOSIT;
(8) Give name of depositors having amount
greater than 4000. SELECT CNAME FROM
DEPOSIT WHERE AMOUNT > 4000;
(9) Give name of customers who opened account
after date '1-12-96'. SELECT CNAME FROM
DEPOSIT WHERE ADATE > ’96-12-01’;

Practical - 2

Practical - 2. Create table with underlined attribute as primary


key and insert sample data in tables. (You may add/Update
Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15
Database Management System (AY 2023-2024)

attributes/values/constrains in the table if required in further


practicals.)

(i) Create Table Job (job_id, job_title, min_sal, max_sal)

COLUMN DATA TYPE


NAME
job_id Varchar2(15)
job_title Varchar2(30)
min_sal Number(7,2)
max_sal Number(7,2)
dept_no Varchar2(10)

CREATE TABLE JOB( Job_id


VARCHAR(15), job_title VARCHAR(30),
min_sal DECIMAL(7,2), max_sal
FLOAT(7,2), dept_no VARCHAR(10) ,
PRIMARY KEY (job_id));

(ii) Create table Employee (emp_no, emp_name, emp_sal, emp_comm,


dept_no)

COLUMN DATA TYPE


NAME
emp_no Number(3)

emp_name Varchar2(30)

emp_sal Number(8,2)

emp_comm Number(6,1)

dept_no Number(3)

hire_date date

CREATE TABLE
EMPLOYEE( Emp_no INT(3),
emp_name VARCHAR(30), emp_sal
DECIMAL(8,2), emp_comm
DECIMAL(6,1), dept_no INT,
hire_date DATE , PRIMARY KEY
(emp_no)); (iii) Create table
Department(dept_no,dept_name,dept
_city).
Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15
Database Management System (AY 2023-2024)

COLUMN NAME DATA TYPE


dept_no Number(3)
dept_name Varchar2(15)
dept_city Varchar2(15)
manager_no Number(3)

CREATE TABLE
DEPARTMENT( Dept_no INT(3),
dept_name VARCHAR(15), dept_city
VARCHAR(15), manager_no INT(3) ,
PRIMARY KEY (dept_no));

(iv) Create table Manager(manager_no, manager_name,emp_no).

COLUMN NAME DATA TYPE


manager_no Number(3)
manager_name Varchar2(15)
emp_no Number(3)

CREATE TABLE
MANAGER( Manager_no
INT(3), manager_name
VARCHAR(15),
emp_no INT(3), PRIMARY KEY (manager_no));

(v) Insert following values in the table Employee.

emp_n emp_nam emp_sa emp_com Hire_dat dep


o e l m e t
_no
101 Smit 800 15-MAR- 20
2003
102 Snehal 1600 300 21-JAN- 25
2005
103 Adama 1100 0 17-NOV- 20
2000
104 Aman 3000 17-DEC- 15
1999
105 Anita 5000 50,000 27-MAR- 10
2008

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

106 Sneha 2450 24,500 31-MAR- 10


2002
107 Anamika 2975 5-SEP- 15
1998

INSERT INTO EMPLOYEE VALUES(101,’SMIT’,800,NULL,20,”2023-03-15”);


INSERT INTO EMPLOYEE VALUES(102,’SNEHAL’,1600,300,25,”2021-01-21”);
INSERT INTO EMPLOYEE VALUES(103,’ADAMA’,1100,0,20,”2000-11-17”);
INSERT INTO EMPLOYEE VALUES(104,’AMAN’,3000,NULL,15,”1999-12-17”);
INSERT INTO EMPLOYEE VALUES(105,’ANITA’,5000,50000,10,”2008-03-27”);
INSERT INTO EMPLOYEE VALUES(106,’SNEHA’,2450,24500,10,”2002-03-31”);
INSERT INTO EMPLOYEE VALUES(107,’ANAMIKA’,2975,NULL,15,”1995-09-05”);

(vi) Insert following values in the table job.

job_id job_name min_sa max_sal dept_no


l
IT_PROG Programmer 20000 30000 25
MK_MGR Marketing 25000 30000 10
manager
FI_MGR Finance manager 21000 25000 20
FI_ACC Account 10000 20000 20
SEL Sales man 6000 10000 15
COMP_OP Computer 10000 15000 25
Operator

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

INSERT INTO JOB VALUES(‘IT_PROG’,’PROGRAMMEER’,20000,30000,25);


INSERT INTO JOB VALUES(‘MK_MGR’,’MARKETING
MANAGER’,25000,30000,10); INSERT INTO JOB VALUES(‘IT_PROG’,’FINANCE
MANAGER’,21000,25000,20); INSERT INTO JOB
VALUES(‘IT_PROG’,’AMOUNT’,10000,20000,20); INSERT INTO JOB
VALUES(‘IT_PROG’,’SALES MEN’,6000,10000,15);
INSERT INTO JOB VALUES(‘IT_PROG’,’COMPUTER
OPERATOR’,10000,15000,25) (vii) Insert following values in the table dept.

dept_no dept_name dept_city manager_no


10 Marketing andheri 1011
15 Sell virar 1051
20 Finance villeparle 1101
25 IT andheri 1151

INSERT INTO DEPARTMENT VALUES(10,’MARKETING’,’ANDHERI’,1011);


INSERT INTO DEPARTMENT VALUES(15,’SELL’,’VIRAR’,1051); INSERT INTO
DEPARTMENT VALUES(20,’FINANCE’,’VILLEPARLE’,1101); INSERT INTO
DEPARTMENT VALUES(25,’IT’,’ANDHERI’,1151);

(viii) Insert following values in the table manager.

manager_n manager_na emp_n


o me o
1011 Marketing 101
1051 Sell 105
1151 Finance 115
1101 IT 110

INSERT INTO MANAGER VALUES(1011,’MARKETING’,101); INSERT INTO


MANAGER VALUES(1051,’SELL’,105); INSERT INTO MANAGER
VALUES(1151,’FINANCE’,115); INSERT INTO MANAGER VALUES(1101,’IT’,110);

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical - 3

Practical - 3. Perform queries involving predicates LIKE,


BETWEEN, IN etc.

(1) Retrieve all data from employee, jobs and deposit.


SELECT * FROM DEPOSIT;
SELECT * FROM Employee;
SELECT * FROM Jobs;

(2) Give details of account no. and deposited rupees of customers having
account opened between dates 01-01-96 and 25-07-96.
SELECT ACTNO, AMOUNT
FROM DEPOSIT
WHERE ADATE BETWEEN “96-01-01” AND “96-07-25”;

(3) Display all jobs with minimum salary is greater than 15000.
SELECT * FROM JOB WHERE min_sal > 15000;

(4) Display name and salary of employee whose department no is 20. Give
alias name to name of employee.
SELECT emp_name AS “Employee Name”, emp_sal
FROM EMPLOYEE;

(5) Display employee no,name and department details of those employee


whose department lies in(10,20).
SELECT emp_name,emp_no,dept_no
FROM EMPLOYEE
WHERE dept_no BETWEEN 10 AND 20;

(6) To study various options of LIKE predicate.


SELECT * FROM EMPLOYEE WHERE emp_name LIKE ‘A%’;
SELECT * FROM EMPLOYEE WHERE emp_name LIKE ‘%ANITA%’;

(7) Display all employee whose name start with ‘A’ and third character is ‘a’.
SELECT *
Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15
Database Management System (AY 2023-2024)

FROM EMPLOYEE
WHERE emp_name LIKE ‘A_A%’;

(8) Display name, number and salary of those employees whose name is 5
characters long and first three characters are ‘Ani’.
SELECT emp_name, emp_no, emp_sal
FROM EMPLOYEE
WHERE emp_name LIKE ‘ANI__’;

(9) Display the non-null values of employees and also employee name
second character should be ‘n’ and string should be 5 character long.
SELECT *
FROM EMPLOYEE
WHERE emp_name IS NOT NULL AND emp_name LIKE ‘_N___’;

(10) Display the null values of employee and also employee name’s third
Character should be ‘a’.
SELECT *
FROM EMPLOYEE
WHERE emp_name IS NULL OR emp_name LIKE ‘__a%’;

(11) What will be output if you are giving LIKE predicate as ‘%\_%’ ESCAPE
‘\’. This query will return rows where column_name contains an underscore
character.

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical - 4

Practical - 4. To Perform various data manipulation


commands, aggregate functions and sorting concept on all
created tables.

(1) List total deposit from deposit.


SELECT sum(AMOUNT) FROM DEPOSIT;

(2) List total loan from karolbagh branch


SELECT sum(AMOUNT) FROM BORROW WHERE
BNAME=’KAROLBAGH’;

(3) Give maximum loan from branch vrce.


SELECT max(AMOUNT) FROM BORROW WHERE BNAME=’VRCE’;

(4) Count total number of customers


SELECT count(CNAME) FROM CUSTOMERS;

(5) Count total number of customer’s cities.


SELECT count(distinct CITY) FROM CUSTOMERS;

(6) Create table supplier from employee with all the columns.
CREATE TABLE Supplier as (SELECT * FROM Employee);

(7) Create table sup1 from employee with first two columns.
CREATE TABLE Sup1 as (SELECT emp_no,emp_name FROM
Employee);

(8) Create table sup2 from employee with no data


CREATE TABLE Sup2 as (SELECT * FROM Employee WHERE
emp_no>200);

(9) Insert the data into sup2 from employee whose second character
should be ‘n’ and string should be 5 characters long in employee
name field.
INSERT INTO Sup2 (SELECT * FROM Employee WHERE
emp_name LIKE ‘_n___’);

(10) Delete all the rows from sup1.


DELETE FROM Sup1;

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

(11) Delete the detail of supplier whose sup_no is 103.


DELETE FROM Supplier WHERE sup_no=103;

(12) Rename the table sup2.


RENAME TABLE Sup2 to Sup3;

(13) Destroy table sup1 with all the


data.
DROP TABLE Sup1;

(14) Update the value dept_no to 10 where second character of emp.


name is ‘m’.
UPDATE Employee set dept_no=10 WHERE emp_name like ‘_m%’;

(15) Update the value of employee name whose employee number is 103.
UPDATE Employee set emp_name=’Mina’ WHERE emp_no=103;

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical - 5

Practical - 5. To study Single-row functions.

(1) Write a query to display the current date. Label the column Date
Query :-

Select sysdate() “Date” from dual;

(2) For each employee, display the employee number, job, salary, and
salary increased by 15% and expressed as a whole number. Label the
column New Salary
Query :-

Select emp_no, job_id, job_title, emp_sal,round( (emp_sal*1.15)) “New


Salary” from (Employee natural join Job);

(3) Modify your query no (2) to add a column that subtracts the old
salary from the new salary. Label the column Increase
Query :-

Select emp_no, job_id, job_title, emp_sal,round( (emp_sal*1.15))


“New Salary”,round((emp_sal*1.15)-emp_sal) “Increase” from
(Employee natural join Job);

(4) Write a query that displays the employee’s names with the first
letter capitalized and all other letters lowercase, and the length of the
names, for all employees whose name starts with J, A, or M. Give
each column an appropriate label. Sort the results by the employees’
names.

Query :-

Select
concat(upper(substr(emp_name,1,1)),lower(substr(emp_name,2)))
“Employee Name”, length(emp_name) “Length” From Employee
where emp_name like ‘J%’ or emp_name like ‘A%’ or emp_name
like ‘M%’ order by emp_name asc;

(5) Write a query that produces the following for each employee:

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

<employee name> earns <salary> monthly


Query :-

Select concat(emp_name,’ earns ‘,emp_sal,’ monthly’) “Employee


Detail” from Employee;

(6) Display the name, hire date, number of months employed and day
of the week on which the employee has started. Order the results by
the day of the week starting with Monday.
Query :-

Select emp_name,hire_date,timestampdiff(month,hire_date,sysdate())
“Months Employed”, Dayname(hire_date) “Starting Day of Week” from
Employee order by weekday(hire_date) asc;

(7) Display the hiredate of emp in a format that appears as Seventh of


June 1994 12:00:00 AM.
Query :-

Select date_format(hire_date,’%D of %M %Y %h:%i:%s %p’) “Hire Date”


from Employee;

(8) Write a query to calculate the annual compensation of all employees


(sal+comm.).
Query :-

Select emp_name,(emp_sal+ifnull(emp_comm,0)) “Annual


Compensation” from Employee;

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical – 6

Practical - 6. Displaying data from Multiple Tables (join)

(1) Add foreign key constrain in 2/3 table wherever possible/required.


Query:-
Update Employee set emp_name=’Vijay’ where emp_no=103;

(2) Give details of customers ANIL.


Query:-
Select * from (((DEPOSIT inner join CUSTOMERS on
DEPOSIT.CNAME=CUSTOMERS.CNAME) inner join BRANCH on
DEPOSIT.BNAME=BRANCH.BNAME) inner join BORROW on
DEPOSIT.CNAME=BORROW.CNAME) where
DEPOSIT.CNAME=’ANIL’;

(3) Give name of customer who are borrowers and depositors and
having living city nagpur
Query:-
Select DEPOSIT.CNAME from ((DEPOSIT inner join BORROW on
DEPOSIT.CNAME=BORROW.CNAME) inner join CUSTOMERS on
DEPOSIT.CNAME=CUSTOMERS.CNAME) where
CUSTOMERS.CITY=’NAGPUR’;

(4) Give city as their city name of customers having same living branch.
Query:-
Select distinct(DEPOSIT.CNAME),CITY “City Name of Customers” from
(CUSTOMERS inner join DEPOSIT on
DEPOSIT.BNAME=CUSTOMERS.CITY);

(5) Write a query to display the name, department number, and


department name for all employees.
Query:-
Select emp_name “Employee Name”, dept_no “Department
Number”, dept_name “Department Name” from (Employee
natural join Department);

(6) Create a unique listing of all jobs that are in department 10. Include
the city of the department in the output.
Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15
Database Management System (AY 2023-2024)

Query:-
Select job_title “Jobs”, dept_city “Department City” from (Job
natural join Department) where dept_no=10;

(7) Write a query to display the employee name, department


number, and department name for all employees who work in
andheri.
Query:-
Select emp_name “Employee Name”, dept_no “Department Number”,
dept_name “Department Name” from (Employee natural join
Department) where dept_city=’andheri’;

(8) Display the employee name and employee number along with their
manager’s name and manager number. Label the columns
Employee, Emp#, Manager, and Mgr#, respectively.
Query:-
Select emp_name “Employee”, emp_no “Emp#”, manager_name
“Manager”, manager_no “Mgr#” from (Employee natural join Manager);

(9) Create a query to display the name and hire date of any employee
hired after employee ‘Vijay’.
Query:-
Select emp_name “Employee Name”, hire_date “Hire Date” from
Employee where hire_date>(select hire_date from Employee where
emp_name=’Vijay’);

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical – 7

Practical - 7. To apply the concept of Aggregating Data using


Group functions.

(1) List total deposit of customer having account date after 1-jan-96.
Query:-
Select sum(AMOUNT) “Total Deposit” from DEPOSIT where
ADATE>’1996-0101’;

(2) List total deposit of customers living in city Nagpur.


Query:-
Select sum(AMOUNT) “Total Deposit” from (DEPOSIT natural join
CUSTOMERS) Where CITY=’NAGPUR’;

(3) List maximum deposit of customers living in bombay.


Query:-
Select max(AMOUNT) “Max Deposit” from (DEPOSIT natural join
CUSTOMERS) where CITY=’BOMBAY’;

(4) Display the highest, lowest, sum, and average salary of all
employees. Label the columns Maximum, Minimum, Sum, and
Average, respectively. Round your results to the nearest whole
number.
Query:-
Select round(max(emp_sal)) “Maximum”, round(min(emp_sal))
“Minimum”, round(sum(emp_sal)) “Sum”, round(avg(emp_sal))
“Average” from Employee;

(5) Write a query that displays the difference between the highest and
lowest salaries. Label the column DIFFERENCE.
Query:-
Select max(emp_sal)-min(emp_sal) “DIFFERENCE” from Employee;

(6) Create a query that will display the total number of employees and,
of that total, the number of employees hired in 2000, 2005, 2006,
and 1998
Query:-
Select count(*) “Total Count”, count(if(year(hire_date)=’2000’,1,NULL))
“Hired in 2000”, count(if(year(hire_date)=’2005’,1,NULL)) “Hired in
2005”, count(if(year(hire_date)=’2006’,1,NULL)) “Hired in 2006”,
count(if(year(hire_date)=’1998’,1,NULL)) “Hired in 1998” from
Employee;

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

(7) Find the average salaries for each department without displaying
the respective department numbers.
Query:-
Select dept_name “Department Name”, avg(emp_sal) “Average” from
(Employee natural join Department) group by dept_name;

(8) Write a query to display the total salary being paid to each job title,
within each department.
Query:-
Select job_title “Job”, sum(emp_sal) “Total Salary” from (Employee
natural join Job) group by job_title

(9) Find the average salaries > 10000 for each department without
displaying the respective department numbers.
Query:-
Select dept_name “Department Name”, avg(emp_sal) “Average
Salary” from (Employee natural join Department) group by
dept_name having avg(emp_sal)>10000;

(10) Display the job and total salary for each job with a total salary
amount exceeding 20000, in which excludes president and sorts
the list by the total salary. Query:- select job_title "Job",
sum(emp_sal) "Total Salary" from (Employee natural join Job)
group by job_title having sum(emp_sal)>20000 order by
sum(emp_sal);

(11) List the branches having sum of deposit more than 20000 and
located in city bombay.
Query:-
Select BNAME “Branch”, sum(AMOUNT) “Sum of Deposit” from
(DEPOSIT natural join BRANCH) where CITY=’BOMBAY’ group by
BNAME having sum(AMOUNT)>20000;

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical - 8

Practical - 8. To solve queries using the concept of sub


query.

(1) Write a query to display the name and hire date of any employee in
the same department as Vijay. Exclude Vijay
Query:-
Select emp_name, hire_date from Employee where dept_no=(select
dept_no from Employee where emp_name=’Vijay’) and emp_name!
=’Vijay’;

(2) Give name of customers who are depositors having same branch city
of Mr. Sunil.
Query:-
Select CNAME from (DEPOSIT natural join BRANCH) where
CITY=(selec
T CITY from (BRANCH natural join DEPOSIT) where
CNAME=’SUNIL’);

(3) Give deposit details and loan details of customer in same city where
Pramod is living.
Query:-
Select ACTNO, DEPOSIT.CNAME, DEPOSIT.BNAME,
DEPOSIT.AMOUNT, ADATE, LOANNO,
BORROW.BNAME,BORROW.AMOUNT, CITY from ((DEPOSIT left
join
BORROW on DEPOSIT.CNAME=BORROW.CNAME) inner join
CUSTOMERS on DEPOSIT.CNAME=CUSTOMERS.CNAME) where
CITY=(select CITY from CUSTOMERS where CNAME=’PRAMOD’);

(4) Create a query to display the employee numbers and names of all
employees who earn more than the average salary. Sort the
results in ascending order of salary.
Query:-
Select emp_no, emp_name from Employee where emp_sal>(select
avg(emp_sal) from Employee) order by emp_sal asc;

(5) Give names of depositors having same living city as Mr. Anil and
having deposit amount greater than 10000
Query:-
Select DEPOSIT.CNAME from (DEPOSIT left join CUSTOMERS on
DEPOSIT.CNAME=CUSTOMERS.C

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

NAME) where CITY=(select CITY from CUSTOMERS where


CNAME=’ANIL’)
and AMOUNT>10000;
(6) Display the name and salary of every employee who reports to Smit.
Query:-
Select emp_name, emp_sal from ((Employee natural join Department)
inner join Manager on
Department.manager_no=Manager.manager_no) where
Department.manager_no=(select manager_no from (Employee natural
join
Manager) where emp_name=’Smit’) and emp_name!=’Smit’;

(7) Display the department number, name, and job for every employee
in the Accounting department.
Query:-
Select Employee.dept_no, emp_name, job_title from (Employee
natural join Job) where dept_no=(select dept_no from Job where
job_title=’Account’);

(8) List the name of branch having highest number of depositors.


Query:-
Select BNAME from DEPOSIT group by BNAME having
count(CNAME)=(select max(counts) from (select count(CNAME) as
counts from DEPOSIT group by
BNAME) as BNAME_COUNTS);

(9) Give the name of cities where in which the maximum numbers of
branches are located.
Query:-
Select CITY from BRANCH group by CITY having
count(BNAME)=(select max© from (select count(BNAME)
as c from BRANCH group by CITY) as CITIES);

(10) Give name of customers living in same city where maximum


depositors are located.
Query:-
Select DEPOSIT.CNAME from (DEPOSIT natural join
CUSTOMERS) where CITY=any(select CITY from
(DEPOSIT natural join CUSTOMERS) group by
CUSTOMERS.CITY having count(*)=(select max© from
(select count(*) as C from (DEPOSIT natural join
CUSTOMERS) group by CUSTOMERS.CITY) as
DEPOSITERS));

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical - 9

Practical - 9. Manipulating Data

(1) Give 10% interest to all depositors.


Query:-
Update DEPOSIT set AMOUNT=AMOUNT+(AMOUNT*0.1);

(2) Give 10% interest to all depositors having branch vrce


Query:-
Update DEPOSIT set AMOUNT=AMOUNT+(AMOUNT*0.1) where
BNAME=’VRCE’;

(3) Give 10% interest to all depositors living in nagpur and having
branch city bombay.
Query:-
Update DEPOSIT set AMOUNT=AMOUNT+(AMOUNT*0.1) where
DEPOSIT.CNAME=any(select CNAME from (select
DEPOSIT.CNAME from
((BRANCH natural join DEPOSIT) inner join CUSTOM
ERS on DEPOSIT.CNAME=CUSTOMERS.CNAME) where
BRANCH.CITY=’BOMBAY’ and CUSTOMERS.CITY=’
NAGPUR’) as subs);

(4) Write a query which changes the department number of all


employees with empno 101 to 104 employees into 30 as current
department number.
Query:-
Update Employee set dept_no=30 where emp_no between 101 and
104;

(5) Transfer 10 Rs from account of Anil to Sunil if both are having same
branch.
Query:-
Update DEPOSIT set AMOUNT=AMOUNT-10 where
CNAME=’ANIL’ and
BNAME=(select * from (select BNAME from DEPOSIT where
CNAME=’SUNIL’) as sub);

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

(6) Give 100 Rs more to all depositors if they are maximum depositors
in their respective branch.
Query:-
Update DEPOSIT set AMOUNT=AMOUNT+100 where
(BNAME,AMOUNT) in (select * from (select BNAME,
max(AMOUNT) from DEPOSIT group by
BNAME) as subs);

(7) Delete depositors of branches having number of customers between


1 to
3.
Query:-
Delete from DEPOSIT where BNAME=any(select * from (select
BNAME from DEPOSIT group by BNAME having count(*) between
1 and 3) as subs);

(8) Delete deposit of Vijay.


Query:-
Delete from DEPOSIT where CNAME=’VIJAY’;

(9) Delete borrower of branches having average loan less than 10000.
Query:-
Delete from BORROW where BNAME=any(select * from (select BNAME
from BORROW group by BNAME having avg(AMOUNT)<10000) as
subs);

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Practical - 10. To apply the concept of security and


privileges.

Practical - 11. To study Transaction control commands

Practical - 12. Write Cursor

Practical - 13. Write Trigger.

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15


Database Management System (AY 2023-2024)

Enrollment No: 220280107126 BE 3rd Sem CE-Dept,LDCE-A’bad-15

You might also like