How to create a SQL DELETE statement

The tutorial describes how to convert a SELECT query to a DELETE query using the Query Builder tool:

Convert a SELECT query to a DELETE query

For demo purposes, we are going to use the Person.Address_copy table which is a copy of the Person.Address table from the AdventureWorks2019 database. First, retrieve data from the table. To do this, in the Database Explorer, right-click the table and select Retrieve Data.

Retrieve data

Next, we will create a query that deletes all records where StateProvinceID equals 79.

1. In the Database Explorer, right-click the table and select Send to > Query Builder.

Alternatively, from the Database Explorer, drag the table to the diagram.

2. Switch to the Where tab to set up the selection condition.

3. Click Set up a filtering condition Add and do the following:

  • Select the StateProvinceID column as an operand.
  • Set equals as a criteria operator.
  • Enter 79 as a value.

Set a filtering condition

Note

If the Tabbed Editor is not displayed, you can open it by clicking View the JOINs created automatically Show Tabbed Editor on the Query toolbar or main menu.

4. Execute the query to preview the result. The records with the StateProvinceID column that equals 79 are displayed.

Retrieve data with the specified condition

5. Change the query type from SELECT to DELETE. To do this, right-click the diagram and select Change Type > Delete. The statement has been converted to the DELETE statement.

Change the query type to DELETE

As you can see, the WHERE condition remains.

6. Switch to the Text view to verify that the script is correct. Then, execute the query.

Review the designed query text

When we check the result, we’ll see that all the records where StateProvinceID was equal to 79 were deleted from the table.

Check the result

Watch the video to see how to create a SQL DELETE statement using dbForge Query Builder for SQL Server.

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Query Builder for SQL Server.
Request a demo

Request a demo

If you consider employing the Query Builder for your business, request a demo to see it in action.
Ready to start using dbForge Query Builder for SQL Server?