0% found this document useful (0 votes)
18 views

Assignment Dbms

Uploaded by

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

Assignment Dbms

Uploaded by

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

Assignment OF Database management of system

SESSION: 2024-25
Submitted in partial fulfilment of
the requirement for the award of
the degree of
Bachelor of Technology In COMPUTER science
ENGINEERING(AI/ML)

SUBMITTED BY : Krishan Beniwal


ROLL. NO. : (23UGBTC35132)
SUBMITTED TO : Ms. Mukta sandhu
SCHEMA

Table Name:- Employee


Empid EmpName Department ContactNo EmailId EmpHeadId
101 Isha E-101 1234567890 [email protected] 105
102 Priya E-104 1234567890 [email protected] 103
103 Neha E-101 1234567890 [email protected] 101
104 Rahul E-102 1234567890 [email protected] 105
105 Abhishek E-101 1234567890 [email protected] 102

CREATE TABLE Employees (


Empid INT PRIMARY KEY,
EmpName VARCHAR(100),
Department VARCHAR(10),
ContactNo VARCHAR(15),
EmailId VARCHAR(100),
EmpHeadId INT
);

INSERT INTO Employees (Empid, EmpName, Department, ContactNo,


EmailId, EmpHeadId) VALUES
(101, 'Isha', 'E-101', '1234567890', '[email protected]', 105),
(102, 'Priya', 'E-104', '1234567890', '[email protected]', 103),
(103, 'Neha', 'E-101', '1234567890', '[email protected]', 101),
(104, 'Rahul', 'E-102', '1234567890', '[email protected]', 105),
(105, 'Abhishek', 'E-101', '1234567890', '[email protected]', 102);
Table :- EmpDept
DeptId DeptName Dept_off DeptHead
E-101 HR Monday 105
E-102 Development Tuesday 101
E-103 Hous Keeping Saturday 103
E-104 Sales Sunday 104
E-105 Purchage Tuesday 104

CREATE TABLE Departments (


DeptId VARCHAR(10) PRIMARY KEY,
DeptName VARCHAR(100),
Dept_off VARCHAR(15),
DeptHead INT
);

INSERT INTO Departments (DeptId, DeptName, Dept_off, DeptHead) VALUES


('E-101', 'HR', 'Monday', 105),
('E-102', 'Development', 'Tuesday', 101),
('E-103', 'House Keeping', 'Saturday', 103),
('E-104', 'Sales', 'Sunday', 104),
('E-105', 'Purchase', 'Tuesday', 104);

Table :- EmpSalary

EmpId Salary IsPermanent


101 2000 Yes
102 10000 Yes
103 5000 No
104 1900 Yes
105 2300 Yes

CREATE TABLE Salaries (


EmpId INT PRIMARY KEY,
Salary INT,
IsPermanent VARCHAR(3)
);

INSERT INTO Salaries (EmpId, Salary, IsPermanent) VALUES


(101, 2000, 'Yes'),
(102, 10000, 'Yes'),
(103, 5000, 'No'),
(104, 1900, 'Yes'),
(105, 2300, 'Yes');

Table :- Project

ProjectId Duration
p-1 23
p-2 15
p-3 45
p-4 2
p-5 30

CREATE TABLE Projects (


ProjectId VARCHAR(10) PRIMARY KEY,
Duration INT );
INSERT INTO Projects (ProjectId, Duration) VALUES
('p-1', 23),
('p-2', 15),
('p-3', 45),
('p-4', 2),
('p-5', 30);

1. Select the detail of the employee whose name start with P.


SQL code:-

SELECT * FROM Employees


WHERE EmpName LIKE 'P%';

OUTPUT

2. Select the detail of employee whose emailId is in gmail.

SELECT * FROM Employees


WHERE EmailId LIKE '%gmail.com';
3. Select the details of the employee who work either for department E-

104 or E-102.

SQL code

SELECT * FROM Employees

WHERE Department = 'E-104' OR Department = 'E-102';

OUTPUT
4. What is the department name for DeptID E-102?

SQL code

ELECT DeptName FROM Departments

WHERE DeptId = 'E-102';

5. List name of all employees whose name ends with a.

SQL code

SELECT EmpName FROM Employees


WHERE EmpName LIKE '%a';

output

6. select the name of the employee whose name's 3rd charactor is 'h'.

SQL code

SELECT EmpName FROM Employees


WHERE SUBSTRING(EmpName, 3, 1) = 'h';
7. How many permanent candidate take salary more than 5000.

SQL code
SELECT COUNT(*) FROM Salaries
WHERE IsPermanent = 'Yes' AND Salary > 5000;

OUTPUT

8. What is total salarythat is paid to permanent employees?

SQL code
SELECT SUM(Salary) FROM Salaries
WHERE IsPermanent = 'Yes';

OUTPUT

9. List the number of department of employees in each project.


SQL code
SELECT p.ProjectId, COUNT(DISTINCT e.Department) AS NumDepartments
FROM Projects p
JOIN EmployeeProjects ep ON p.ProjectId = ep.ProjectId
JOIN Employees e ON ep.EmpId = e.Empid
GROUP BY p.ProjectId;
OUTPUT

10. How many project started and finished in the same year

SQL code
SELECT COUNT(*) FROM Projects
WHERE YEAR(StartDate) = YEAR(EndDate);

OUTPUT

You might also like