Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 2 4 4 3 SQL Server Assignment 7 Total Points: 1 0 0 Write the code for each of the following and submit a

CS2443 SQL Server
Assignment 7
Total Points: 100
Write the code for each of the following and submit a textfile with the scripts in the
DropBox for the assignment in Moodle.
Questions 1-5 are each worth 8 points and Questions 6-11 are each worth 10 points.
COMPANY database
The Company databse stores data about its employees, their departments and assignments
and projects in the following tables.
Employee
empSSN
empLName
empFName
empGender
empAddress
empDOB
empSalary
empDeptNum
empSuperSSN
Assignment
workempSSN
workProjNumber
workHours
workHoursplanned
Project
projNumber
projName
projLocation
projdeptNum
Department
deptnum deptName
deptMgrSSN
deptMgr_startdate
Dept_Location
Deptnum
deptlocation
The Company is organized in separate departments. Each department has a unique
deptnum and has a department name. Each department has a manager and the date on
which the manager started managing the department. The managers social security
number is stored in the department table and it provides a foreign key link to the specific
employee that manages a department.
Each department may have multiple city locations within the company. The primary key
of the dept_location table is the composite of deptnum and the deptlocation. The deptnum
also serves as a foreign key link back to the departments table.
The Employee table stores employee information. Each employee is identified by
empSSN. Each employee works in a department. Some employees also mange
departments. A department can have 0,1 or more assigned employees. Through the
empDeptNum we have a foreign key relationship with the Department table. Each
department has 1 manager and so an employee may have a manager . Some employees
maybe manager themselves.
The Project table contains details about each project that the company has. Projects for
the company are controlled by departments. Each project has a project number
(projNumber) and they are kept track of by project name (projName) and by location. A
department may have 0,1 or more projects, and a project belongs to 1 and only one
department.
The Assignment table keeps track of project assignments. Each employee is assigned to
work on 0,1 or more projects. It associates the employee and project tables. The primary
key is a composite of the primary key from the employee table combined with the
primary key from the project table.
Using the Company database, write SQL scripts for the following cases:
1. The Department table stores information about departments within the company.
The deptMgr_startdate column stores the start date on which an employee started
working as a department manager.Write a query to display the date for the
manager that has worked the longest as a department manager. Label the output
column as Longest Working Manager.
2. Accountants working on the companys annual budgeting process needs to know
the average salary for employees and the sum of all employee salaries. All
information is in the Employee table.
3. The companys VP for Project Management needs to know the number of
projects each department is working on based on the information stored in the
Project table.
4. The Companys VP for Project Management wants a list of projects located in
Oklahoma or supervised by the Production department.
5. The Assignment table stores data about the hours that employees are working on
specific projects. A senior project manager desires a list of employees(last and
first names) who are currently working on project numbers 10,20 or 30.Use a
subquery approach.
6. Management is concerned about work productivity. Write a query that produces a
listing of each employee who has not worked on a sinlge project till date. The
employees name (first and last names) and their department names are to be
displayed.
7. The companys senior project manager needs to access information about
departments that manage projects for a specific set of projects, namely those
located in Oklahoma or Texas. Create a view named department_projects that
includes the department number, department name , project name and location.
Write a Select statement that displays all rows that are accessible through the
view.
8. Demonstrate the use of the view named department_projects(created above) for
the senior manager by writing a Select statement to query the view to display all
row information for projects belonging to department 3.
9. Create a table named sales_order. The table should have an identity column
named so_number. There are 2 other columns the sales order value(so_value)
and the SSN for the employee who enters the sales order information
(so_empSSN). Using INSERT statements insert 3 rows into the sales_order table.
Write a SELECT statement that displays all the information in the sales_order
table.
10 A. Write a stored procedure named replace_work_hours that updates the
workHours column in the Assignment table. The proce

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions