DBM S Practicals
DBM S Practicals
DBM S Practicals
Practical - 1
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) );
DEPOSIT
BRANCH
VRCE NAGPUR
AJNI NAGPUR
KAROLBAGH DELHI
CHANDI DELHI
DHARAMPETH NAGPUR
M.G.ROAD BANGLORE
ANDHERI BOMBAY
VIRAR BOMBAY
NEHRU PLACE DELHI
POWAI BOMBAY
ANIL CALCUTTA
SUNIL DELHI
MEHUL BARODA
MANDAR PATNA
MADHURI NAGPUR
PRAMOD NAGPUR
SANDIP SURAT
SHIVANI BOMBAY
KRANTI BOMBAY
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:
Practical - 2
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)
CREATE TABLE
DEPARTMENT( Dept_no INT(3),
dept_name VARCHAR(15), dept_city
VARCHAR(15), manager_no INT(3) ,
PRIMARY KEY (dept_no));
CREATE TABLE
MANAGER( Manager_no
INT(3), manager_name
VARCHAR(15),
emp_no INT(3), PRIMARY KEY (manager_no));
Practical - 3
(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;
(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.
Practical - 4
(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);
(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___’);
(15) Update the value of employee name whose employee number is 103.
UPDATE Employee set emp_name=’Mina’ WHERE emp_no=103;
Practical - 5
(1) Write a query to display the current date. Label the column Date
Query :-
(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 :-
(3) Modify your query no (2) to add a column that subtracts the old
salary from the new salary. Label the column Increase
Query :-
(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:
(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;
Practical – 6
(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);
(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;
(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’);
Practical – 7
(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’;
(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;
(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;
Practical - 8
(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
(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’);
(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);
Practical - 9
(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);
(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);
(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);
(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);