Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me write these 2 queries? (Database code is located beneith the questions) 4.8. Create a view that includes the labor costs associated with

Please help me write these 2 queries? (Database code is located beneith the questions)

4.8. Create a view that includes the labor costs associated with each job. Include Customer ID and

Name.

4.9. Use the View from 4.8 to create a query that includes the total labor cost for each customer.

Order by Customer ID.

CREATE TABLE TCustomers

(

intCustomerID INTEGER NOT NULL

,strFirstName VARCHAR(30) NOT NULL

,strLastName VARCHAR(30) NOT NULL

,strAddress VARCHAR(30) NOT NULL

,strCity VARCHAR(30) NOT NULL

,intStateID INTEGER NOT NULL

,strZipcode VARCHAR(30) NOT NULL

,CONSTRAINT TCustomers_PK PRIMARY KEY( intCustomerID )

)

CREATE TABLE TStates

(

intStateID INTEGER NOT NULL

,strState VARCHAR(30) NOT NULL

,CONSTRAINT TStates_PK PRIMARY KEY( intStateID )

)

CREATE TABLE TJobStatus

(

intJobStatusID INTEGER NOT NULL

,strJobStatus VARCHAR(30) NOT NULL

,CONSTRAINT TJobStatus_PK PRIMARY KEY( intJobStatusID )

)

CREATE TABLE TJobs

(

intJobID INTEGER NOT NULL

,intCustomerID INTEGER NOT NULL

,intJobStatusID INTEGER NOT NULL

,strJobDescription VARCHAR(2000) NOT NULL

,dteStartDate DATE NOT NULL

,dteEndDate DATE NOT NULL

,CONSTRAINT TJobs_PK PRIMARY KEY( intJobID )

)

CREATE TABLE TWorkers

(

intWorkerID INTEGER NOT NULL

,strFirstName VARCHAR(30) NOT NULL

,strLastName VARCHAR(30) NOT NULL

,dteDateOfHire DATE NOT NULL

,monHourlyRate MONEY NOT NULL

,CONSTRAINT TWorkers_prk PRIMARY KEY( intWorkerID )

)

CREATE TABLE TJobWorkers

(

intJobID INTEGER NOT NULL

,intWorkerID INTEGER NOT NULL

,intTotalHours INTEGER NOT NULL

,CONSTRAINT TJobWorkers_PK PRIMARY KEY( intJobID,intWorkerID )

)

CREATE TABLE TSkills

(

intSkillId INTEGER NOT NULL

,strSkillDescription VARCHAR(30) NOT NULL

,CONSTRAINT TSkills_PK PRIMARY KEY( intSkillId )

)

CREATE TABLE TWorkerSkills

(

intWorkerID INTEGER NOT NULL

,intSkillId INTEGER NOT NULL

,CONSTRAINT TWorkerSkills_PK PRIMARY KEY( intWorkerID,intSkillID )

)

CREATE TABLE TMaterials

(

intMaterialID INTEGER NOT NULL

,strMaterialName VARCHAR(30) NOT NULL

,monMaterialCost MONEY NOT NULL

,CONSTRAINT TMaterials_PK PRIMARY KEY( intMaterialID)

)

CREATE TABLE TJobMaterials

(

intMaterialID INTEGER NOT NULL

, intJobID INTEGER NOT NULL

,intQuantity INTEGER NOT NULL

,CONSTRAINT TJobMaterials_PK PRIMARY KEY( intJobID, intMaterialID)

)

ALTER TABLE TWorkerSkills ADD CONSTRAINT TWorkerSkills_TSkills_FK

FOREIGN KEY ( intSkillId ) REFERENCES TSkills ( intSkillId )

ALTER TABLE TWorkerSkills ADD CONSTRAINT TWorkerSkills_TWorkers_FK

FOREIGN KEY ( intWorkerID) REFERENCES TWorkers ( intWorkerID )

ALTER TABLE TJobs ADD CONSTRAINT TJobs_TJobStatus_FK

FOREIGN KEY ( intJobStatusID ) REFERENCES TJobStatus ( intJobStatusID )

ALTER TABLE TJobs ADD CONSTRAINT TJobs_TCustomers_FK

FOREIGN KEY ( intCustomerID ) REFERENCES TCustomers ( intCustomerID )

ALTER TABLE TJobMaterials ADD CONSTRAINT TJobMaterials_TMaterials_FK

FOREIGN KEY ( intMaterialID) REFERENCES TMaterials ( intMaterialID)

ALTER TABLE TJobMaterials ADD CONSTRAINT TJobMaterials_TJobs_FK

FOREIGN KEY ( intJobID ) REFERENCES TJobs ( intJobID )

ALTER TABLE TJobWorkers ADD CONSTRAINT TJobWorkers_TJobs_FK

FOREIGN KEY ( intJobID ) REFERENCES TJobs ( intJobID)

INSERT INTO TStates (intStateID,strState)

VALUES (1,'Ohio')

,(2,'Alaska')

,(3,'Iowa')

,(4,'Florida')

,(5,'Kentucky')

,(6,'Indiana')

,(7,'New York')

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions