0% found this document useful (0 votes)
2 views29 pages

Dbms Assin 1

The document outlines a series of practical exercises for a BCA semester IV assignment focused on Database Management Systems (DBMS). It includes tasks on retrieving, updating, and managing records in various tables such as EMPLOYEES, Client_master, Teacher, and Sales, along with SQL syntax examples. Additionally, it covers advanced topics like rollback, commit commands, and privileges management for database users.

Uploaded by

up65prince
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views29 pages

Dbms Assin 1

The document outlines a series of practical exercises for a BCA semester IV assignment focused on Database Management Systems (DBMS). It includes tasks on retrieving, updating, and managing records in various tables such as EMPLOYEES, Client_master, Teacher, and Sales, along with SQL syntax examples. Additionally, it covers advanced topics like rollback, commit commands, and privileges management for database users.

Uploaded by

up65prince
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

BCA Semester : IVth

BCA402: Practical
(DBMS- Assignment’s)

Submitted To Submitted By
Vandana Verma Prahlad Nishad
Roll No.: 40
Page 1 of 29
1. (Exercise on retrieving records from the table) EMPLOYEES
(Employee_Id, First_Name, Last_Name, Email, Phone_number, Hire_Date,
Job_Id, Salary, Commission_Pct, Manager_Id, Department_Id)

Page 2 of 29
( a) Find out the employee id, names, salaries of all the employees

( b) List out the employees who works under manager 100

( c) Find the names of the employees who have a salary greater than or equal
to 4800

( d) List out the employees whose last name is ‘AUSTIN’

Page 3 of 29
( e) Find the names of the employees who works in departments 60,70 and
80.
Syntax: select Employee_Id, First_Name, Last_Name from Employees where
Department_Id IN ('D60','D70','D80');

( f ) Display the unique Manager_Id.

Syntax: select DISTINCT (Manager_Id) from Employees;

Page 4 of 29
2. (Exercise on updating records in table)
Create Client_master with the following fields(ClientNO, Name, Address, City,
State, bal_due)
Syntax : Create table Client_master(ClientNO varchar(20), Name varchar(50),
Address varchar(20), City varchar(20), State varchar(20), bal_due varchar(20)); (
a ) Insert five records
Syntax: insert into Clint_master
values('C120','M','Durgakund','Varanasi','UP','6000');

( b ) Find the names of clients whose bal_due> 5000 .

Page 5 of 29
( c ) Change the bal_due of ClientNO “ C123” to Rs. 5100
Syntax: update Client_Master set Bal_Due=5100 where ClientNo='C123';

( d ) Change the name of Client_master to Client12 .


Syntax : rename table client_master to client12;

( e ) Display the bal_due heading as “BALANCE”.


Syntax : select ClientNo, Bal_Due as Balance from Client12;

Page 6 of 29
3. Rollback and Commit commands
Create Teacher table with the following fields(Name, DeptNo, Date of joining,
DeptName, Location, Salary)
( a ) Insert five records
Syntax: insert into Teacher
values('Sneha','D400','20180715','Arts','Varanasi','3000');

Page 7 of 29
( b ) Give Increment of 25% salary for Science Department .
Syntax : update teacher set Salary = salary +(salary*0.25) where deptname =
'Science';

( c ) Perform Rollback command

Page 8 of 29
( d ) Give Increment of 15% salary for Commerce Department
Syntax : update teacher set Salary = salary +(salary*0.15) where deptname =
'Commerce';

( e ) Perform commit command

4 . (Exercise on order by and group by clauses)


Create Sales table with the following fields( Sales No, Salesname, Branch,
Salesamount, DOB)
Syntax: create table Sales ( Sales_No varchar(10) Primary Key, Salesname
varchar(20), Branch varchar(20), Salesamount varchar(20), DOB varchar(20));

Page 9 of 29
( a ) Insert five records
Syntax : insert into sales
values('S001','SRISHTI','VARANASI','50000','09DEC2003');

Page 10 of 29
( b ) Calculate total salesamount in each branch
Syntax : select SUM(Salesamount) as Total_Sum from sales;

( c ) Calculate average salesamount in each branch .


Syntax: select AVG(Salesamount) as Total_Sales_Avg from sales;

( d ) Display all the salesmen, DOB who are born in the month of December as
day in character format i.e. 21-Dec-09.
Syntax: SELECT SALESNAME,DOB from sales
where(SUBSTRING(DOB,4,3))='DEC';

Page 11 of 29
( e ) Display the name and DOB of salesman in alphabetical order of the
month.
Syntax: select SalesName,DOB from sales Order by SUBSTRING(DOB,4,3);

Page 12 of 29
5. Create an Emp table with the following fields:
(EmpNo, EmpName, Job, Basic, DA, HRA,PF, GrossPay, NetPay) (Calculate DA
as 30% of Basic and HRA as 40% of Basic)
Syntax: create table emp(EmpNo varchar(20), EmpName varchar(20), Job
varchar(20),Basic varchar(20));

( a ) Insert Five Records and calculate GrossPay and NetPay. Syntax:


insert into emp values('E001','Pravin','HR','50000');

#Updating Attributes DA, HRA, PF, Gross pay, Net Pay ?


# Adding coloumn to table and Updating Attributes DA
Syntax: alter table employeeadd(Emp_DA varchar(20)(6));
Syntax: update Emp set Emp_DA=(30/100)*Basic;
Page 13 of 29
# Adding coloumn to table and Updating Attributes HRA
Syntax: alter table emp add(HRA varchar(20));
Syntax: update Emp set HRA=(40/100)*Basic;

# Adding coloumn to table and Updating Attributes PF


Syntax: alter table emp add (PF varchar(20));

Page 14 of 29
Syntax: update Emp set pf= (12/100)*Basic;

# Adding coloumn to table and Updating Attributes Gross Pay


Syntax: alter table emp add (Grosspay varchar(20));
Syntax: update Emp set grosspay= (hra+da+basic);

Page 15 of 29
# Adding coloumn to table and Updating Attributes Net Pay Syntax: alter
table emp add (netpay varchar(20));
Syntax: update Emp set netpay= grosspay- pf;

( b ) Display the employees whose Basic is lowest in each department .

Page 16 of 29
Syntax: SELECT EmpNo,job, min(basic) from emp group by EmpNo having
min(basic);

( c ) If NetPay is less than <Rs. 10,000 add Rs. 1200 as special allowances .
Syntax: update emp set netpay=netpay+1200 where netpay<10000;

( d ) Display the employees whose GrossPay lies between 10,000 & 20,000
Syntax : mysql> select *from emp where GrossPay between 10000 and 20000;

Page 17 of 29
( e ) Display all the employees who earn maximum salary .
Syntax: select * from emp where grosspay = (select max(grosspay) from emp);

Page 18 of 29
6. Employee Database
An Enterprise wishes to maintain a database to automate its operations.
Enterprise is divided into certain departments and each department consists
of employees. The following two tables describes the automation schemas
Dept (deptno, dname, loc)
Emp (empno, ename, job, mgr, hiredate, sal, comm, deptno)
Syntax: create table Dept (deptno varchar(20) Primary Key, dname
varchar(20), loc varchar(20));

Syntax : create table Empl (empno varchar(20) Primary Key, ename


varchar(20), job varchar(20), mgr varchar(20), hiredate date, sal varchar(20),
comm varchar(20), deptno varchar(20), Foreign Key(deptno) references
Dept(deptno));

Page 19 of 29
Syntax : INSERT INTO EMPL VALUES('E001', 'NISHU',
'SELLING','SHRI','20011202','50000','1000','D001');

a) Update the employee salary by 15%, whose experience is greater than 10


years.

Page 20 of 29
Syntax: update empl set sal=sal+(sal*0.15) where
(2023substr(hiredate,1,4))>10;

b) Delete the employees, who completed 30 years of service.


Syntax : delete from empl where (2023-substr(hiredate,1,4))>=30;

c) Display the manager who is having maximum number of employees


working under him?
Syntax: Syntax: create view mgrcount as select mgr, count(empno) total from
empl group by mgr;

Page 21 of 29
Syntax: select mgr from mgrcount where total in (select max(total) from
mgrcount);

d) Create a view, which contain employee names and their manager


Syntax: create view employee_manager as select e1.ename ,e2.empno from
empl e1, empl e2 where e1.mgr=e2.empno;

7. Using Employee Database perform the following queries


a) Determine the names of employee, who earn more than their managers.
Syntax: SELECT ENAME FROM EMPL WHERE SAL>MGRSAL;

b) Determine the names of employees, who take highest salary in their


departments.

Page 22 of 29
Syntax: SELECT EmpNo,job, max(sal) from empl group by EmpNo having
max(sal);

c) Determine the employees, who are located at the same place.


Syntax : select ename,dname from empl , dept where
empl.deptno=dept.deptno order by dname;

d) Determine the employees, whose total salary is like the minimum Salary of
any department.
Syntax : select empno, ename, sal from empl where sal in(select min(sal) from
empl group by deptno);

e) Determine the department which does not contain any employees.

Page 23 of 29
Syntax: select deptno, dname from dept where deptno not in(select deptno
from empl);

8.Consider the following tables namely “DEPARTMENTS” and “EMPLOYEES”


Their schemas are as follows,
Departments ( dept _no , dept_ name , dept_location ); Employees
( emp_id , emp_name , emp_salary,dept_no);
a) Develop a query to grant all privileges of employees table into departments
table Syntax: mysql> create user 'Vandana'@'localhost' identified by
'123456'; Query OK, 0 rows affected (0.04 sec)
mysql> grant all on empl.dept to Vandana@localhost;
Query OK, 0 rows affected (0.01 sec) mysql> show
grants for Vandana@localhost;

Page 24 of 29
b) Develop a query to grant some privileges of employees table into
departments table Syntax: mysql> grant all on dept.* to
Vandana@localhost; Query OK, 0 rows affected (0.01 sec) mysql> grant all
on dept to Vandana@localhost; Query OK, 0 rows affected (0.01 sec)
mysql> show grants for Vandana@localhost;

Page 25 of 29
c) Develop a query to revoke all privileges of employees table from
departments table
mysql> Revoke all privileges on table dept from Vandana@localhost;
Query OK, 0 rows affected (0.01 sec) mysql> show grants for
Vandana@localhost;

d) Develop a query to revoke some privileges of employees table from


departments table.
Syntax: mysql> REVOKE IF EXISTS SELECT ON empl.dept FROM
Vandana@localhost;
Query OK, 0 rows affected (0.01 sec) mysql>
show grants for Vandana@localhost;

Page 26 of 29
e) Write a query to implement the save point. Syntax: mysql> savepoint dept;

9. Using the tables “DEPARTMENTS” and “EMPLOYEES” perform the following


queries
a) Display the employee details, departments that the departments are
same in both the emp and dept.
Syntax : select ename, dname from dept,empl where
empl.deptno=dept.deptno;

Page 27 of 29
b) Display the employee name and Department name by implementing a
left outer join.
select empl.ename, dept.dname from empl LEFT JOIN dept ON
empl.deptno=dept.deptno;

c) Display the employee name and Department name by implementing a


right outer join.
select empl.ename, dept.dname from empl RIGHT JOIN dept ON
empl.deptno=dept.deptno;

Page 28 of 29
d) Display the details of those who draw the salary greater than the
average salary.
Syntax : Select empno,sal from empl where sal> (select avg(sal) from emp);

*************************

Page 29 of 29

You might also like