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

DB Lab 11 - Muneeb Ashraf

Uploaded by

Muneeb Ashraf
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)
9 views6 pages

DB Lab 11 - Muneeb Ashraf

Uploaded by

Muneeb Ashraf
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/ 6

Lab 11

“DataBase SQL”

Submitted by:
Muneeb Ashraf

Subject:
Database - SQL
Sem. & Dept:
BSSE-4A (Morning)

Date:
4-12-2024

Submitted to:
Madam. Syeda Maryam Tahir

1 | Page
Lab # 11:
CREATE DATABASE LabTask11;

USE LabTask11;

CREATE TABLE Department (


DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50)
);
CREATE TABLE Employeee (
EmployeID INT PRIMARY KEY,
EmployeName VARCHAR(50),
DepartmentID INT,
FOREIGN KEY (DepartmentID) REFERENCES
Department(DepartmentID)
);
CREATE TABLE Project (
ProjectID INT PRIMARY KEY,
ProjectName VARCHAR(50),
EmployeID INT,
FOREIGN KEY (EmployeID) REFERENCES Employeee(EmployeID)
);

INSERT INTO Department (DepartmentID, DepartmentName) VALUES


(1, 'HR'),
(2, 'Finance'),
(3, 'IT'),
(4, 'Marketing'),
(5, 'Sales');
INSERT INTO Employeee (EmployeID, EmployeName, DepartmentID)
VALUES
(1, 'Ali', 1),
(2, 'Hassan', 2),
(3, 'Sara', 3),
(4, 'Ahmed', 4),
(5, 'Zara', 5);
INSERT INTO Project (ProjectID, ProjectName, EmployeID) VALUES
(1, 'Project A', 1),
(2, 'Project B', 2),
(3, 'Project C', 3),
(4, 'Project D', 4),
(5, 'Project E', 5);

SELECT e.EmployeID, e.EmployeName, d.DepartmentName


FROM Employeee e
JOIN Department d ON e.DepartmentID = d.DepartmentID;

SELECT p.ProjectID, p.ProjectName, e.EmployeName


FROM Project p
JOIN Employeee e ON p.EmployeID = e.EmployeID;

SELECT e.EmployeID, e.EmployeName, d.DepartmentName,


p.ProjectName
FROM Employeee e

2 | Page
JOIN Department d ON e.DepartmentID = d.DepartmentID
LEFT JOIN Project p ON e.EmployeID = p.EmployeID;

SELECT e.EmployeID, e.EmployeName, d.DepartmentName


FROM Employeee e
LEFT JOIN Department d ON e.DepartmentID = d.DepartmentID;

SELECT d.DepartmentID, d.DepartmentName, e.EmployeName


FROM Department d
LEFT JOIN Employeee e ON d.DepartmentID = e.DepartmentID;

SELECT e.EmployeID, e.EmployeName, d.DepartmentName


FROM Employeee e
RIGHT JOIN Department d ON e.DepartmentID = d.DepartmentID
UNION
SELECT e.EmployeID, e.EmployeName, d.DepartmentName
FROM Employeee e
LEFT JOIN Department d ON e.DepartmentID = d.DepartmentID;

Question # 01:
Retrieve the list of employees along with
their department names.

Question # 02
Retrieve a list of projects along with the names of employees
assigned to them.

3 | Page
Question # 03
Retrieve the list of employees, their
department names, and the projects they are assigned to.

4 | Page
Question # 04:
Retrieve a list of all employees and their
department names. Include employees who are not assigned

to any department.

Question # 05:
Retrieve a list of all departments and
the employees in those departments. Include departments

with no employees.

5 | Page
Question # 06:
Retrieve a list of all employees and their
department names. Include employees without a department
and
departments without employees.

6 | Page

You might also like