SQL Server UPDATE statement is used to update data, the following is a detailed description of the syntax aspects of SQL Server update statements, hoping to give you a better understanding of SQL Server Update statements.
In real-world applications, data changes in the database are unavoidable. Typically, most of the data in almost all user databases is modified to some degree. To modify a database record in a SQL Server database, you need to use the UPDATE statement, which exists to change the existing data in the database. This statement, while having some complex options, is indeed one of the easiest to learn. This is because, in most cases, the high-level portion of this statement is rarely used. In the view of the user, the UPDATE statement is used only 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 a new row.
The syntax for the SQL Server UPDATE statement is as follows:
Update <table_name> Set <column_name> = <value> where <search_condition>
The following is a brief introduction to the syntax options:
The name of the <table_name> table. The table contains the columns to modify the values
<column_name> the name of the column for which you want to modify data
<value> new values to enter into the column
<search_condition> This is the most important part of the UPDATE statement. By specifying a good search condition, you can limit the number of rows that are modified in the table. If you do not specify a search condition, SQL Server modifies all rows in the table with the new value
Example:
Now let's see how to actually modify some of the rows in the table. We have a column in the table that uses unique values to differentiate each row in the table. Therefore, we can easily write down the UPDATE statement, only to change the corresponding author of the row of data. As follows:
Copy Code code as follows:
Update users set phone=78789831 where number = 231;
For example, now we need to increase the price of each item in the supermarket table by 11%, is it necessary to write a separate UPDATE statement for each line? In the present case, there may not be many update statements to write, but if it is a larger table, this is a problem. Therefore, the answer is in the negative. All you have to do is write an UPDATE statement that does not specify the row to update, as follows:
Copy Code code as follows:
Update shop Set Priceprice = Price *. 11;