set = where..."."/> set = where...".">

Home >Database >Mysql Tutorial >How to write sql update statement

How to write sql update statement

清浅
清浅Original
2019-05-09 10:12:3845224browse

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 2d8f501bba7dbcabf64f6c8aceccc3b7 set f4c55dd52f1b37a9debd48ac1ff8dbb5 = 8487820b627113dd990f63dd2ef215f3 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>

Syntax introduction

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

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

8487820b627113dd990f63dd2ef215f3: The new value to be entered into the column

d27c8605733fdd4527c90adf380f31d8 : 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;

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 ;

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!

Statement:
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

Related articles

See more