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 use update statement in SQL Server

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

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to use update statement in SQL Server, the content is very detailed, interested friends can refer to, hope to be helpful to you.

In the real application, the change of the data in the database is inevitable. Usually, most of the data in almost all user databases has to be modified to some extent. If you want to modify the database records in the SQL Server database, you need to use the UPDATE statement, and the UPDATE statement exists to change the existing data in the database. Although this statement has some complex options, it is one of the easiest to learn. This is because in most cases, the advanced parts of this statement are rarely used. From the user's point of view, the UPDATE statement is only used to change the data in the specified row. But the actual internal situation is that SQL Server deletes the old data row from the table and inserts the new row.

The syntax of the SQL Server UPDATE statement is as follows:

Update set = where

The following is an introduction to syntax options:

The name of the table. The table contains the column to modify the value, the name of the column to modify the data to enter into the column, which 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 have been modified. If you do not specify search criteria, SQLServer will modify all rows in the table with the new values

Example:

Now let's look at how to actually modify some of the rows in the table. We have a column in the table that uses a unique value to distinguish each row in the table. Therefore, we can easily write down the UPDATE statement and change only the row of data corresponding to a certain author. As follows:

The copy code is as follows: update users set phone=78789831 where number = 231

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

Update shop set priceprice = price * .11

On how to use update statements in SQL Server to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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