The tutorial describes how to convert a SELECT query to a DELETE query using the Query Builder tool:
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.
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 Add and do the following:
Note
If the Tabbed Editor is not displayed, you can open it by clicking 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.
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.
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.
When we check the result, we’ll see that all the records where StateProvinceID was equal to 79 were deleted from the table.
Watch the video to see how to create a SQL DELETE statement using dbForge Query Builder for SQL Server.