Get the App
SLTechnology News&Howtos  ›  Database  › 

How to write sql update statement

Shulou Source: shulou.com Published: 2022-06-01 03:52:24 10月16日 Update

This article will explain in detail how to write sql update statements for everyone, Xiaobian thinks it is quite practical, so share it with you for a reference, I hope you can gain something after reading this article.

Update statements in SQL databases are completed using UPDATE statements, the role of UPDATE statements is to change the existing data in the database, so as to achieve the purpose of updating data.

Data changes in databases are inevitable in real-world applications. Usually, most of the data in almost all user databases needs to be modified to some extent. In SQL Server database to modify database records, you need to use UPDATE statement, UPDATE statement is to change the existing data in the database and exist. This sentence, although it has some complex options, is one of the easiest to learn. This is because in most cases, the high-level part of this statement is rarely used. From the user's point of view, UPDATE statements are simply used to change the data in the specified row. But the actual internal situation is that SQL Server deletes old rows of data from tables and inserts new rows.

UPDATE syntax

update set = where

Introduction to grammar

: The name of the table containing the column whose value you want to modify

: Name of column whose data you want to modify

: New value to enter into column

This is the most important part of the UPDATE statement. By specifying a good search condition, you can limit the number of rows in the table that are modified. If you do not specify search criteria, SQL Server modifies all rows in the table with the new values

Examples:

Now let's see how to actually modify some rows in the table. We have a column in the table with a unique value that distinguishes each row in the table. Therefore, we can easily write UPDATE statements that change only the row corresponding to an author. As follows:

The code is as follows:

update users set phone=78789831 where number =231;

For example, if we want to increase the price of each item in the supermarket table by 11%, is it necessary to write a separate UPDATE statement for each row? In this case, there may not be a lot of UPDATE statements to write, but if it's a larger table, this is a problem. So the answer is no. All you have to do is write an UPDATE statement that does not specify the rows to update, as follows:

The code is as follows:

update shop set priceprice = price * .11 ; About sql update statement how to write to share here, I hope the above content can have some help for everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Statement data database update situation one line code just name actual more condition user article syntax this is part search good complex Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information MySQL Huawei Shulou Technology