Cheap Jerseys Cheap NFL Jerseys Cheap NFL Jerseys Cheap Football jerseys Cheap NFL Jerseys Wholesale Jerseys Cheap NHL Jerseys Cheap Jerseys From China Cheap MLB Jerseys Cheap Jerseys Cheap Jerseys Cheap Jerseys Wholesale Jerseys SQL Update Statement - WTMatter

SQL Update Statement

SQL Update Statement

This is a detailed guide of the SQL Update Statement. Learn how you can update the database table records and can change the column values using the Update Query.

Use of SQL Update Statement

The SQL Update Statement is used whenever you want to change or modify the table records of your database. This way you can change any column value of any table row. The Update Statement is mostly used with SQL WHERE Clause to find out the right table cell to change the value. You can also update the value of multiple columns as well as multiple rows at the same time in a single Update Query.

Update Syntax

The basic syntax for the SQL Update Query is written below. Here we’re updating the col_1 and col_2, respectively with values val_1 and val_2 in the table_name where the condition is True.

Note. It is not necessary to use the WHERE Clause but if you won’t use it will update the column values for the entire table rows.

SQL Update Query Examples

Here in this section, we’ve given three different examples for the SQL Update Query. Each example is different in its own kind and illustrates a unique use case.

For demonstration, we’ll use the demo database in which we have the standards table. The existing state of the table is shown in the screenshot given below.

SQL Update Statement Demo Database Table

There are 7 columns in the table and the last two columns have the NULL values set for all of the records.

  • In the first query, we’ll update the values for two columns of a single table record.
  • In the second query, we’ll update a single column for multiple rows.
  • In the third and last example query, we’ll update the value for one null column for the entire table to illustrate the importance of the WHERE clause.

Note. You must put the strings in either single or double quotes but need not put integer values in any kind of quote.

Updating Single Record

Query 1.


SQL Update Statement Simple Example

The above query updates the column values for the column standard_full_name and standard_short_name for the table row with ID 10.

Updating Multiple Records

Query 2.


SQL Update Multiple Records

The above query updated the column standard_description values for all the table records with ID either four or less than four. There are four table records with IDs 1, 2, 3 and 4 that are updated after the execution of this query.

Updating All Table Records

Query 3.


SQL Update Statement Without WHERE Clause Example

This example illustrates why you should always use the Update Query with WHERE clause and shows that you may end up in updating the entire table’s column values if you won’t use it. In the above query, the standard_comments column is updated for the entire table.

The following screenshot shows the table state after the execution of all the queries specified in the above examples.

Updated Table State

I hope you find this guide useful. If so, do share it with others who are willing to learn SQL. If you have any questions related to this article, feel free to ask them in the comments section.

Helpful Associated Guides.

Also, don’t forget to Subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

Your email address will not be published. Required fields are marked *