Dbms Assin 1
Dbms Assin 1
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
( c) Find the names of the employees who have a salary greater than or equal
to 4800
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');
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');
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';
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';
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';
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;
( 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));
Page 14 of 29
Syntax: update Emp set pf= (12/100)*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;
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));
Page 19 of 29
Syntax : INSERT INTO EMPL VALUES('E001', 'NISHU',
'SELLING','SHRI','20011202','50000','1000','D001');
Page 20 of 29
Syntax: update empl set sal=sal+(sal*0.15) where
(2023substr(hiredate,1,4))>10;
Page 21 of 29
Syntax: select mgr from mgrcount where total in (select max(total) from
mgrcount);
Page 22 of 29
Syntax: SELECT EmpNo,job, max(sal) from empl group by EmpNo having
max(sal);
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);
Page 23 of 29
Syntax: select deptno, dname from dept where deptno not in(select deptno
from empl);
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;
Page 26 of 29
e) Write a query to implement the save point. Syntax: mysql> savepoint dept;
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;
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