Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write sql update statement

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report