Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

{MICROSOFT SQL SERVER} Write a query to list the total Charge to the customer for each job. Calculate the total charge to the customer as

{MICROSOFT SQL SERVER} Write a query to list the total Charge to the customer for each job. Calculate the total charge to the customer as the total cost of materials + total Labor costs + 30% Profit.

Need help creating the above query from the database below. Thanks.

-- Drop Tables

IF OBJECT_ID('TJobMaterials') IS NOT NULL DROP TABLE TJobMaterials

IF OBJECT_ID('TMaterials') IS NOT NULL DROP TABLE TMaterials

IF OBJECT_ID('TVendors') IS NOT NULL DROP TABLE TVendors

IF OBJECT_ID('TJobWorkers') IS NOT NULL DROP TABLE TJobWorkers

IF OBJECT_ID('TJobs') IS NOT NULL DROP TABLE TJobs

IF OBJECT_ID('TWorkerSkills') IS NOT NULL DROP TABLE TWorkerSkills

IF OBJECT_ID('TWorkers') IS NOT NULL DROP TABLE TWorkers

IF OBJECT_ID('TSkills') IS NOT NULL DROP TABLE TSkills

IF OBJECT_ID('TCustomers') IS NOT NULL DROP TABLE TCustomers

IF OBJECT_ID('TStatuses') IS NOT NULL DROP TABLE TStatuses

IF OBJECT_ID('TStates') IS NOT NULL DROP TABLE TStates

-- --------------------------------------------------------------------------------

-- --------------------------------------------------------------------------------

-- Create Database

-- --------------------------------------------------------------------------------

CREATE TABLE TJobs

(

intJobID INTEGER NOT NULL

,intCustomerID INTEGER NOT NULL

,intStatusID INTEGER NOT NULL

,dtmStartDate DATETIME NOT NULL

,dtmEndDate DATETIME NOT NULL

,strJobDesc VARCHAR(8000) NOT NULL

,CONSTRAINT TJobs_PK PRIMARY KEY ( intJobID )

)

CREATE TABLE TCustomers

(

intCustomerID INTEGER NOT NULL

,strFirstName VARCHAR(255) NOT NULL

,strLastName VARCHAR(255) NOT NULL

,strAddress VARCHAR(255) NOT NULL

,strCity VARCHAR(255) NOT NULL

,intStateID INTEGER NOT NULL

,strZip VARCHAR(255) NOT NULL

,strPhoneNumber VARCHAR(255) NOT NULL

,CONSTRAINT TCustomer_PK PRIMARY KEY ( intCustomerID )

)

CREATE TABLE TStatuses

(

intStatusID INTEGER NOT NULL

,strStatus VARCHAR(255) NOT NULL

,CONSTRAINT TStatuses_PK PRIMARY KEY ( intStatusID )

)

CREATE TABLE TJobMaterials

(

intJobMaterialID INTEGER NOT NULL

,intJobID INTEGER NOT NULL

,intMaterialID INTEGER NOT NULL

,intQuantity INTEGER NOT NULL

,monTotalCost MONEY NOT NULL

,CONSTRAINT TCustomerJobMaterials_PK PRIMARY KEY ( intJobMaterialID )

)

CREATE TABLE TMaterials

(

intMaterialID INTEGER NOT NULL

,strDescription VARCHAR(255) NOT NULL

,monCost MONEY NOT NULL

,intVendorID INTEGER NOT NULL

,CONSTRAINT TMaterials_PK PRIMARY KEY ( intMaterialID )

)

CREATE TABLE TVendors

(

intVendorID INTEGER NOT NULL

,strVendorName VARCHAR(255) NOT NULL

,strAddress VARCHAR(255) NOT NULL

,strCity VARCHAR(255) NOT NULL

,intStateID INTEGER NOT NULL

,strZip VARCHAR(255) NOT NULL

,strPhoneNumber VARCHAR(255) NOT NULL

,CONSTRAINT TVendors_PK PRIMARY KEY ( intVendorID )

)

CREATE TABLE TJobWorkers

(

intJobWorkerID INTEGER NOT NULL

,intJobID INTEGER NOT NULL

,intWorkerID INTEGER NOT NULL

,intHoursWorked INTEGER NOT NULL

,CONSTRAINT TCustomerJobWorkers_PK PRIMARY KEY ( intJobWorkerID )

)

CREATE TABLE TWorkers

(

intWorkerID INTEGER NOT NULL

,strFirstName VARCHAR(255) NOT NULL

,strLastName VARCHAR(255) NOT NULL

,strAddress VARCHAR(255) NOT NULL

,strCity VARCHAR(255) NOT NULL

,intStateID INTEGER NOT NULL

,strZip VARCHAR(255) NOT NULL

,strPhoneNumber VARCHAR(255) NOT NULL

,dtmHireDate DATETIME NOT NULL

,monHourlyRate MONEY NOT NULL

,CONSTRAINT TWorkers_PK PRIMARY KEY ( intWorkerID )

)

CREATE TABLE TWorkerSkills

(

intWorkerSkillID INTEGER NOT NULL

,intWorkerID INTEGER NOT NULL

,intSkillID INTEGER NOT NULL

,CONSTRAINT TWorkerSkills_PK PRIMARY KEY ( intWorkerSkillID )

)

CREATE TABLE TSkills

(

intSkillID INTEGER NOT NULL

,strSkill VARCHAR(255) NOT NULL

,strDescription VARCHAR(255) NOT NULL

,CONSTRAINT TSkills_PK PRIMARY KEY ( intSkillID )

)

CREATE TABLE TStates

(

intStateID INTEGER NOT NULL

,strState VARCHAR(255) NOT NULL

,CONSTRAINT TStates_PK PRIMARY KEY ( intStateID )

)

-- --------------------------------------------------------------------------------

-- Establish Referential Integrity

-- --------------------------------------------------------------------------------

--

-- # Child Parent Column

-- - ----- ------ ---------

-- 1 TJobs TCustomers intCustomerID

-- 2 TJobs TStatuses intStatusID

-- 3 TCustomers TStates intStateID

-- 4 TJobMaterials TJobs intJobID

-- 5 TJobMaterials TMaterials intMaterialID

-- 6 TMaterials TVendors intVendorID

-- 7 TVendors TStates intStateID

-- 8 TJobWorkers TJobs intJobID

-- 9 TJobWorkers TWorkers intWorkerID

-- 10 TWorkers TStates intStateID

-- 11 TWorkerSkills TWorkers intWorkerID

-- 12 TWorkerSkills TSkills intSkillID

-- Add data

-- 1

ALTER TABLE TJobs ADD CONSTRAINT TJobs_TStatuses_FK

FOREIGN KEY ( intStatusID ) REFERENCES TStatuses ( intStatusID )

-- 2

ALTER TABLE TJobs ADD CONSTRAINT TJobs_TCustomers_FK

FOREIGN KEY ( intCustomerID ) REFERENCES TCustomers ( intCustomerID )

-- 3

ALTER TABLE TCustomers ADD CONSTRAINT TCustomers_TStates_FK

FOREIGN KEY ( intStateID ) REFERENCES TStates ( intStateID )

-- 4

ALTER TABLE TJobMaterials ADD CONSTRAINT TJobMaterials_TJobs_FK

FOREIGN KEY ( intJobID ) REFERENCES TJobs ( intJobID )

-- 5

ALTER TABLE TJobMaterials ADD CONSTRAINT TJobMaterials_TMaterials_FK

FOREIGN KEY ( intMaterialID ) REFERENCES TMaterials ( intMaterialID )

-- 6

ALTER TABLE TMaterials ADD CONSTRAINT TMaterials_TVendors_FK

FOREIGN KEY ( intVendorID ) REFERENCES TVendors ( intVendorID )

-- 7

ALTER TABLE TVendors ADD CONSTRAINT TVendors_TStates_FK

FOREIGN KEY ( intStateID ) REFERENCES TStates ( intStateID )

-- 8

ALTER TABLE TJobWorkers ADD CONSTRAINT TJobWorkers_TJobs_FK

FOREIGN KEY ( intJobID ) REFERENCES TJobs ( intJobID )

-- 9

ALTER TABLE TJobWorkers ADD CONSTRAINT TJobWorkers_TWorkers_FK

FOREIGN KEY ( intWorkerID ) REFERENCES TWorkers ( intWorkerID )

-- 10

ALTER TABLE TWorkers ADD CONSTRAINT TWorkers_TStates_FK

FOREIGN KEY ( intStateID ) REFERENCES TStates ( intStateID )

-- 11

ALTER TABLE TWorkerSkills ADD CONSTRAINT TWorkerskills_TWorkers_FK

FOREIGN KEY ( intWorkerID ) REFERENCES TWorkers ( intWorkerID )

-- 12

ALTER TABLE TWorkerSkills ADD CONSTRAINT TWorkerskills_TSkills_FK

FOREIGN KEY ( intSkillID ) REFERENCES TSkills ( intSkillID )

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

2. To compare the costs of alternative training programs.

Answered: 1 week ago