T-SQL: DELETE FROM

Please see my other Database Development articles.

Performing DELETE using a JOIN

One of the most common actions necessary when deleting records is to delete some using relationships.
One example of deleting via a relationship is utilizing a JOIN to isolate a recordset targeted for deletion.

In this example, I’ll first create two temporary tables which I’ll then populate with test records.
Then, I’ll display the contents of both table to serve as a references.

delete-from_before

With the test tables populated with “parent” and “child” records, I’ll then JOIN the two tables to isolate and delete those children linked to the first parent.

delete-from_after

Here a view of the code.

delete-from_code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s