An explanation of the use of SQL Server UPDATE statements

Source: Internet
Author: User

The SQL Server UPDATE statement is used to update the data, which gives you a detailed description of the syntax of the SQL Server Update statement, and hopefully allows you to learn more about SQL Server update statements.

Data changes in a database are unavoidable in real-world applications. Typically, most of the data in almost any user database is modified to some extent. In a SQL Server database where you want to modify database records, you need to use the UPDATE statement, which is to change the existing data in the database. Although this statement has some complex options, it is indeed one of the easiest to learn. This is because in most cases, the high-level part of this statement is seldom used. In the view of the user, the UPDATE statement is used only to change the data in the specified row. However, the actual internal situation is that SQL Server removes the old data rows from the table and inserts the new rows.

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

Update <table_name> Set <column_name> = <value> where <search_condition>

Here is an introduction to syntax options:

The name of the <table_name> table. The table contains the columns for which you want to modify 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 within 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 rows in the table. We have a column in our table that uses unique values to differentiate each row in the table. Therefore, we can easily write the UPDATE statement and change only the row of data that corresponds to an author. As follows:

Copy CodeThe code is as follows:
Update users set phone=78789831 where number = 231;

For example, now we have 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 a lot of update statements to write, but if it's a larger table, that's a problem. So the answer is no. All you have to do is write an UPDATE statement that does not specify the row to update, as follows:

Copy CodeThe code is as follows:
Update shop Set Priceprice = Price *. 11;

An explanation of the use of SQL Server UPDATE statements

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.