Question: Assignment 3 : Testing Advanced MS SQL Stored Procedure Creation ( 7 . 5 % ) Individual Assignment Objective: This advanced lab assignment aims to
Assignment : Testing Advanced MS SQL Stored Procedure Creation
Individual Assignment
Objective:
This advanced lab assignment aims to test your skills in creating and working with advanced
stored procedures in MS SQL You will create a database named AdvancedDB, add tables,
insert data into these tables, and then write advanced stored procedures based on the given
questions.
Step : Create Database
Create database
CREATE DATABASE AdvancedDB;
GO
Use the database
USE AdvancedDB;
GO
Step : Create Tables
Create the following tables: Employees, Departments, Projects, and Assignments.
Create Employees table
CREATE TABLE Employees
EmployeeID INT PRIMARY KEY,
FirstName NVARCHAR
LastName NVARCHAR
HireDate DATE,
DepartmentID INT
;
GO
Create Departments table
Assignment : Testing Advanced MS SQL Stored Procedure Creation
Individual Assignment
CREATE TABLE Departments
DepartmentID INT PRIMARY KEY,
DepartmentName NVARCHAR
;
GO
Create Projects table
CREATE TABLE Projects
ProjectID INT PRIMARY KEY,
ProjectName NVARCHAR
StartDate DATE,
EndDate DATE
;
GO
Create Assignments table
CREATE TABLE Assignments
AssignmentID INT PRIMARY KEY,
EmployeeID INT,
ProjectID INT,
AssignmentDate DATE,
Role NVARCHAR
FOREIGN KEY EmployeeID REFERENCES EmployeesEmployeeID
FOREIGN KEY ProjectID REFERENCES ProjectsProjectID
;
Assignment : Testing Advanced MS SQL Stored Procedure Creation
Individual Assignment
GO
Step : Insert Data
Insert sample data into the Employees, Departments, Projects, and Assignments tables.
Insert data into Departments table
INSERT INTO Departments DepartmentID DepartmentName
VALUES
'Human Resources'
'Engineering'
'Marketing';
GO
Insert data into Employees table
INSERT INTO Employees EmployeeID FirstName, LastName, HireDate,
DepartmentID
VALUES
'Alice', 'Johnson',
'Bob', 'Smith',
'Charlie', 'Brown', ;
GO
Insert data into Projects table
INSERT INTO Projects ProjectID ProjectName, StartDate, EndDate
VALUES
'Project Alpha',
'Project Beta', ;
Assignment : Testing Advanced MS SQL Stored Procedure Creation
Individual Assignment
GO
Insert data into Assignments table
INSERT INTO Assignments AssignmentID EmployeeID, ProjectID,
AssignmentDate, Role
VALUES
'Developer'
'Manager'
'Tester';
GO
Step : Create below Advanced Stored Procedure using the above DB
Create a stored procedure named GetProjectAssignments that retrieves all
assignments for a specific project, including employee details and role.
Create a stored procedure named UpdateProjectEndDate that updates the end
date of a project and logs the change in a new table ProjectLog.
Create a stored procedure named GetDepartmentEmployeeCount that
retrieves the number of employees in each department.
Create a stored procedure named InsertNewEmployee that inserts a new
employee and their initial assignment within a transaction.
Create a stored procedure named GetEmployeesWithMultipleAssignments that
retrieves employees who have more than one assignment.
Create a stored procedure named UpdateEmployeeDepartment that updates
an employee's department and logs the change in a new table EmployeeLog.
Create a stored procedure named GetProjectsWithNoCurrentEmployees that
retrieves projects with no current employees assigned.
Create a stored procedure named GetEmployeeAssignmentHistory that
retrieves the assignment history of a specific employee.
Create a stored procedure named GetOverdueProjects that retrieves projects
whose end date has passed but are not yet completed.
Create a stored procedure named GetEmployeesByRole that retrieves all
employees assigned to a specific role.
Assignment : Testing Advanced MS SQL Stored Procedure Creation
Individual Assignment
Create a stored procedure named GetEmployeeCountByRole that retrieves the
number of employees for each role.
Create a stored procedure named GetEmployeesWithNoCurrentAssignments
that retrieves employees who do not have any current assignments.
Create a stored procedure named GetProjectAssignmentStatistics that
retrieves statistics on the number of assignments per project.
Submission Requirements:
Combine all SQL scripts and screenshots of the output into a single document.
Ensure that each task's script and corresponding output screenshot are clearly
labeled.
Grading Criteria:
Correctness of SQL scripts and procedures.
Accuracy of the output.
Completeness of the submission tasks completed
Proper formatting and organization of the docum
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
