CRUD Statements  «Prev  Next»

DELETE Using a Joined Table — Exercise

Create a DELETE Statement using values from another table

Objective: Practice creating a DELETE statement using values from another table.

Exercise scoring

This is a 10-point self-assessment. Compare your SQL with the model answer and rubric after submitting. The website does not execute SQL or automatically grade your response.

Instructions

Practice environment: Write SQL for the sample tables in the dbo schema. Submitting displays your text and a model answer; it does not run database commands. If you test independently, use a disposable practice database.

Assume Tasks.TaskID is a primary key, Timesheets.TaskID references it, WeekEndingDate has the date type, and Hours is numeric. The five displayed timesheet rows form the complete sample. For the UPDATE exercise, the listed employee/task/date combination identifies one row.

Using the course project as an example, the Timesheets table looks like this:
EmployeeIDClientIDTaskIDWeekEndingDateHours
1171012026-06-0130
1171022026-06-0850
231012026-06-1540
3321032026-06-0145
3321032026-06-0835

The Tasks table looks like this:
TaskID Description Chargeable
101 Vacation 0
102 General 1
103 Programming 1
The task is to delete all timesheet rows for tasks that are not chargeable, as listed in the Tasks table. Construct a DELETE statement with an explicit INNER JOIN that uses both tables to delete matching rows from the Timesheets table, as described above.
Self-assessment rubric
PointsCriterion
3Target only Timesheets (the ts alias) for deletion.
3Join Timesheets to Tasks on TaskID.
3Filter Tasks.Chargeable = 0.
1Use valid Transact-SQL and identify the two affected timesheet rows.

Submitting the exercise

Type or paste your Transact-SQL statement into the text box below, then click Submit button to submit them and view a results page.