Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views3 pages

Practical 2 Memo

The document outlines SQL commands to create a database named Practical2_2025, including tables for Department, Employee, and Project, along with their respective fields and relationships. It also includes commands to insert data into these tables and various SELECT queries to retrieve specific information such as employee salaries, project details, and department names. Additionally, it features updates to employee years of service and generates unique codes based on employee names.

Uploaded by

mk365org
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)
25 views3 pages

Practical 2 Memo

The document outlines SQL commands to create a database named Practical2_2025, including tables for Department, Employee, and Project, along with their respective fields and relationships. It also includes commands to insert data into these tables and various SELECT queries to retrieve specific information such as employee salaries, project details, and department names. Additionally, it features updates to employee years of service and generates unique codes based on employee names.

Uploaded by

mk365org
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/ 3

CREATE DATABASE Practical2_2025;

USE Practical2_2025;

-- Creating Employee table Second

-- Create Department table First

CREATE TABLE Department(


deptNo VARCHAR(50) PRIMARY KEY NOT NULL,
deptName VARCHAR(255),
managerNo VARCHAR(50)
);

CREATE TABLE Employee(


empID VARCHAR(50) PRIMARY KEY NOT NULL,
empLName VARCHAR(255),
emplFName VARCHAR(255),
deptNo VARCHAR(50) NOT NULL,
jobTitle VARCHAR(255),
years INT,
salary MONEY,
commission MONEY,
FOREIGN KEY (deptNo) REFERENCES Department(deptNo)
);

-- Create Project table Third

CREATE TABLE Project(


projectNo VARCHAR(50) PRIMARY KEY NOT NULL,
projectName VARCHAR(255),
deptNo VARCHAR(50),
prManager VARCHAR(50),
noEmp INT,
prStartdate SMALLDATETIME,
prEnddate SMALLDATETIME,
FOREIGN KEY (deptNo) REFERENCES Department(deptNo)
);

-- Insert values into Department table

INSERT INTO Department(deptNo, deptName, managerNo)


VALUES
('DPT_01','FINANCIAL','EMP_20'),
('DPT_02','SALES','EMP_30'),
('DPT_03','OPERATIONS','EMP_50'),
('DPT_04','ADMIN','EMP_20');

SELECT * FROM Department;

-- Insert values into Employee table

INSERT INTO Employee(empID, empLName, emplFName, deptNo, jobTitle, years, salary,


commission)
VALUES
('EMP_10', 'WALL', 'CHRIS', 'DPT_03', 'EDITOR', '2', '35000.00', NULL),
('EMP_20', 'ABBA', 'ZACK', 'DPT_02', 'ADVERTISING SALES EXECUTIVE', '5', '35000.00',
'32500.00'),
('EMP_30', 'SILVA', 'JOEL', 'DPT_01', 'MANAGER EDITOR', '12', '65000.00', NULL),
('EMP_40', 'SILVA', 'ANNIE', 'DPT_01', 'FINANCIAL MANAGER', '12', '45000.00', NULL),
('EMP_50', 'KRUGER', 'SHAUN', 'DPT_02', 'SALES MANAGER', '12', '40000.00',
'57000.00'),
('EMP_60', 'WELGEMOED', 'GERRIE', 'DPT_02', 'SALES EXECUTIVE', '4', '25000.00',
'35000.00'),
('EMP_70', 'ROBINSON', 'DARRYL', 'DPT_03', 'OPERATIONS MANAGER', '12', '40000.00',
NULL),
('EMP_80', 'MILLER', 'ANTHONY', 'DPT_03', 'GRAPHIC DESIGNER', '3', '20000.00', NULL),
('EMP_90', 'NOBLE', 'SHONEEZ', 'DPT_04', 'RECEPTIONIST AND PA', '2', '15000.00',
NULL);

SELECT * FROM Employee;

-- Insert values into Project table

INSERT INTO Project(projectNo, projectName, deptNo, prManager, noEmp, prStartdate,


prEnddate)
VALUES
('PR_001','NEW CONTRACT-SAB','DPT_02','EMP_50','3','2013/01/10 00:00','2013/03/30
00:00'),
('PR_002','GENERAL ADMIN SYSTEM','DPT_03','EMP_40','2','2013/04/01 00:00','2013/12/01
00:00'),
('PR_003','APPLICATIONS SUPPORT','DPT_03','EMP_40','5','2013/02/01 00:00','2013/05/31
00:00'),
('PR_004','ACCOUNT PROGRAMMING','DPT_01','EMP_70','3','2013/01/01 00:00','2013/07/31
00:00'),
('PR_005','NEW CONTRACT-ABSA','DPT_02','EMP_50','3','2013/01/01 00:00','2013/06/30
00:00');

SELECT * FROM Project;

-- Question 2

SELECT empLName, salary


FROM Employee;

-- Question 3

SELECT projectName, prStartdate, prEnddate


FROM Project
WHERE MONTH(prStartdate) = 4;

-- Question 4

SELECT deptName
FROM Department
LEFT JOIN Project
ON Project.deptNo = Department.deptNo
WHERE Department.deptNo NOT IN (SELECT deptNo FROM Project);

-- Question 5

SELECT empLName, salary


FROM Employee
ORDER BY salary ASC;
-- Question 6

SELECT MAX(salary) AS 'Highest Salary', MIN(salary) AS 'Lowest Salary',


COUNT(salary) AS 'Number of Salaries'
FROM Employee;

-- Question 7

SELECT empLName, emplFName, years, salary, Department.deptName


FROM Employee
LEFT JOIN Department
ON Department.deptNo = Employee.deptNo
WHERE salary BETWEEN 10000 AND 30000;

-- Question 8

SELECT empLName, emplFName, commission


FROM Employee
WHERE commission IS NOT NULL
ORDER BY empLName DESC;

-- Question 9

SELECT * FROM Project


WHERE projectName LIKE '%ADMIN%';

-- Question 10

SELECT
CONCAT(LEFT(empLName,3), RIGHT(emplFName,3),'-', '2014') AS 'Editor Code'
FROM Employee;

-- Question 11

SELECT years + 1 AS 'Years'


FROM Employee;

--OR

UPDATE EMPLOYEE SET YEARS = YEARS + 1;


SELECT YEARS FROM EMPLOYEE;

You might also like