Home > Database > Mysql Tutorial > body text

How to write sql update statement

清浅
Release: 2020-09-16 11:56:34
Original
45213 people have browsed it

The update statement in the SQL database must be completed using the UPDATE statement. The function of the UPDATE statement is to change the existing data in the database to achieve the purpose of updating the data. Its syntax is "update set = where...".

How to write sql update statement

##The update statement in the SQL database must be completed using the UPDATE statement. The function of the UPDATE statement is to change the existing data in the database to achieve the purpose of updating the data.

In real applications, data changes in the database are inevitable. Typically, most of the data in almost all user databases will be modified to some degree. If you want to modify database records in a SQL Server database, you need to use the UPDATE statement. The UPDATE statement exists to change the existing data in the database. This statement, 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 perspective, the UPDATE statement is only used to change the data in the specified row. But what actually happens internally is that SQL Server deletes old data rows from the table and inserts new rows.

UPDATE syntax

update <table_name> set <column_name> = <value> where <search_condition>
Copy after login

Syntax introduction

: The name of the table, which contains the information to be modified Column of value

: The name of the column whose data is to be modified

: The new value to be entered into the 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 conditions, SQL Server will modify all rows in the table with new values

Example:

Now let’s see how to actually modify a certain row in the table Some lines. We have a column in the table that uses a unique value that distinguishes each row in the table. Therefore, we can easily write an UPDATE statement to change only the row of data corresponding to an author. As follows:

The code is as follows:

update users set phone=78789831 where number =231;
Copy after login

For example, now we want to increase the price of each item in the supermarket table by 11%. Is it necessary to write an independent UPDATE statement for each row? ? In the current situation, there may not be many UPDATE statements to write, but if it is a larger table, this will be a problem. So the answer is no. All you have to do is write an UPDATE statement that does not specify the rows to be updated, like this:

The code is as follows:

update shop set priceprice = price * .11 ;
Copy after login

The above is the detailed content of How to write sql update statement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template