0% found this document useful (0 votes)
14 views6 pages

DBMS Practical

Question for practical board

Uploaded by

sriwastavsidd
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)
14 views6 pages

DBMS Practical

Question for practical board

Uploaded by

sriwastavsidd
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/ 6

Disclaimer : Do not Claim ownership

of this document without proof,


doing so will 100% result in harmful
side effect including but not limited
to an untimely departure from planet
Earth .This warning is especially
made for a very specific creature
(Agniva). If you are not this very
specific creature you can ignore this
warning or can you ?(cue the Vsauce music)
1.

a. create database CompanyDB;

b. create tableDepartments (

DeptID intprimary key,

DeptName varchar(100) );

c. create table Employees (

EmpID int primary key,

Name varchar(50),

DeptID int,

Salary decimal(10, 2),

JoiningDate date,

City varchar(50),

Foreign key (DeptID) references Departments(DeptID) );

2.

a. insert into Departments (DeptID, DeptName) values

(1, 'HR'),

(2, 'IT'),

(3, 'Finance');

b. insert intoEmployees (EmpID, Name, DeptID, salary, JoiningDate, City)


values

(101, 'Rohan', 1, 45000, '2018-05-10', 'Delhi'),

(102, 'Sneha', 2, 62000, '2021-03-15', 'Mumbai'),

(103, 'Amit', 3, 53000, '2019-11-20', 'Bangalore'),

(104, 'Raj', 1, 47000, '2020-07-08', 'Kolkata'),


(105, 'Kiran', 2, 72000, '2022-09-25', 'Delhi'),

(106, 'Anjali', 3, 48000, '2017-04-01', 'Mumbai'),

(107, 'Priya', 3, 67000, '2022-08-15', 'Bangalore'),

(108, 'Varun', 2, 75000, '2020-01-20', 'Delhi'),

(109, 'Sunita', 1, 49000, '2023-04-18', 'Mumbai');

3.

a.select * fromEmployees where salary > 50000;

b. select * from Employees

where joiningdate between'2019-01-01' AND '2021-01-01';

c. select case when city is not null then 'City Specified'

else 'City Not Specified'

end as city_status,

count(*) as employee_count

from Employees

group by city_status;

4.

a. delete from Employees where EmpID = [Employee_ID];

b. update Employees

set salary = [New_Salary] where EmpID = [Employee_ID];

5. select * from Employees where DeptID = 2 and salary > 60000;

6. select * from Employees

Where (DeptID = 1 or salary < 50000 )and DeptID != 3;

7. select EmpID, Name, salary * salary as squared_salary


from Employees where salary > 50000;

8. select EmpID, upper(Name) as Namefrom Employees

where Name LIKE 'S%' and DeptID IN (1, 2);

9. select EmpID, Name,

Extract(month from JoiningDate) AS join_month,

Extract(year from JoiningDate) AS join_year

from Employees

where JoiningDate between'2019-01-01' and '2022-12-31';

10. select DeptID,

count(*) as total_employees,

avg(salary) as average_salary

from Employees

group by DeptID

having count(*) > 1;

11. selectDeptID,

sum(salary) as total_salary

from Employees

group by DeptID

order by total_salary desc;

12. select EmpID, Name,

round(Salary, -3) as RoundedSalary

from Employees

order by Salary desc;


13. select Employees.EmpID, Employees.Name, Departments.DeptName

From Employees

Join Departments on Employees.DeptID = Departments.DeptID

where Employees.salary > 60000;

14. select EmpID, Name, Salary

from Employees where Salary between 50000 and 70000

and DeptID <> 1;

15. Select EmpID, Name,

instr(Name, 'a') as FirstOccurrenceOfA

from Employees where DeptID = 2

and instr(Name, 'a') > 0;

16. select EmpID, Name, JoiningDate

from Employees

where JoiningDate > '2020-12-31'

and City in ('Delhi', 'Mumbai');

17. alter table Employees add Experience int;

update Employees

set Experience = year(curdate()) - year(JoiningDate);

18. select DeptID,

Sum (Salary) as TotalSalary,

count(EmpID) as NumberOfEmployees

from Employees

group by DeptID having sum(Salary) > 100000;


19. select EmpID, Name, Salary

from Employees

where Salary > (select avg(Salary) from Employees where DeptID =


Employees.DeptID);

20. select EmpID, Name,

dayname(JoiningDate) as DayOfWeekJoined,

month(JoiningDate) as MonthOfJoining

from Employees

group by month(JoiningDate), EmpID, Name, DayOfWeekJoined

order by JoiningDate;

You might also like