SQL Server UPDATE statement Usage Details, sqlupdate

Source: Internet
Author: User

SQL Server UPDATE statement Usage Details, sqlupdate

The SQL Server UPDATE statement is used to UPDATE data. The following describes the SQL Server UPDATE statement syntax in detail. We hope you can learn more about SQL Server UPDATE statements.

In real-world applications, data changes in databases are inevitable. Generally, most data in almost all user databases must be modified to some extent. To modify Database records in the SQL Server database, you must use the UPDATE statement 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 advanced part of this statement is rarely used. In the user's opinion, the UPDATE statement is only used to change the data in the specified row. However, the actual internal situation is that SQL Server deletes old data rows from the table and inserts new rows.

The SQL Server UPDATE statement syntax is as follows:

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

The following describes the syntax options:

<Table_name> name of the table. This table contains the columns whose values are to be modified.
<Column_name> name of the column to be modified
<Value> new value to be entered in 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 modified rows in the table. If you do not specify a search condition, SQLServer uses the new value to modify all rows in the table.

Example:

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

Copy codeThe Code is as follows:
Update users set phone = 78789831 where number = 231;

For example, if 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 is a problem. Therefore, the answer is no. All you have to do is write an UPDATE statement that does not specify the row to be updated, as shown below:

Copy codeThe Code is as follows:
Update shop set priceprice = price *. 11;


SQL SERVER Update statement usage

Update HUIY set membership level = 'Senior reference' where membership level = '95'

The statement is correct. We recommend that you back up the database before changing the operation.

SQL Server update statement

UPDATE <Table> SET <column name = UPDATE value (2 | 3)> [WHERE <UPDATE condition>]

"Update value (2 | 3)" generates a bool value, and then assigns this bool value to the column to be updated.
 

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.