How to create a SQL UPDATE statement

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

Convert a SELECT query to a UPDATE query

For demo purposes, we are going to use the table Production.Document from the AdventureWorks2019 database. First, retrieve data from the table to view the data. To do this, in the Database Explorer, right-click the table and select Retrieve Data.

Retrieve data

Next, we will create a query that updates all records for the Owner column where it is equal to 217, and change it to 218.

1. In the Database Explorer, right-click the table and select Send to > Query Builder. The SELECT query for the table was created.

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

2. Switch to the Where tab to specify the selection condition.

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

  • Select the Owner column as an operand.
  • Set equals as a criteria operator.
  • Enter 217 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 Owner column that equals 217 are displayed.

Retrieve data with the specified condition

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

Change the query type to UPDATE

6. On the diagram, select the Owner column and set its value to 218 on the Update tab.

Change the value to 218

7. Execute the query and view the result.

As you can see, all the records where Owner was equal to 217 were changed to 218.

Execute the query and view the result

Watch the video to see how to create a SQL UPDATE statement using the Query Builder tool.

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?