SQL Server Update statement usage

Source: Internet
Author: User

 

The update statement is used to create an update query and change the Field Values in the specified table based on the specified conditions. The update statement does not generate a result set, and you cannot cancel this operation after updating the query update records.

Syntax: Update table set newvalue where criteria

Description: The table parameter specifies the table name, which contains the data to be changed.
Newvalue is an expression used to calculate the value of a specific field in the update record to be inserted.
The criteria parameter is an expression used to specify the updated record. Only records that match the expression are updated.

Name

Update-replace the column/field values in the table

Syntax
UPDATE table SET col = expression [, ...]    [ FROM fromlist ]    [ WHERE condition ]
Input
Table
Name of an existing table.
Column
Name of the column/field in the table.
Expression
Assign a valid value or expression to a column or field.
Fromlist
Postgres is a non-standard extension that allows columns/fields in other tables to appear in the where condition.
Condition
See the SELECT statement to obtain a further description of the WHERE clause.
Output
Update #
The returned information is successful. # indicates the number of updated rows. If # is equal to 0, no row is updated.
Description

Update changes the declared column/Field Values of all rows that meet the condition. Only the columns/fields to be modified need to appear in the statement.

Array references use the same syntax as select. That is to say, a single array element, a range of array elements, or the entire array can be updated using a query statement.

To change a table, you must have the write permission on it. You must also have the read permission on any table mentioned in the where condition.

Usage

Replace the word "drama" in the field kind with "dramatic:

UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';SELECT * FROM films WHERE kind = 'Dramatic' OR kind = 'Drama'; code  |     title     | did | date_prod  |   kind   | len-------+---------------+-----+------------+----------+------- BL101 | The Third Man | 101 | 1949-12-23 | Dramatic | 01:44 P_302 | Becket        | 103 | 1964-02-03 | Dramatic | 02:28 M_401 | War and Peace | 104 | 1967-02-12 | Dramatic | 05:57 T_601 | Yojimbo       | 106 | 1961-06-16 | Dramatic | 01:50 DA101 | Das Boot      | 110 | 1981-11-11 | Dramatic | 02:29
Compatibility sql92

Sql92 defines some different syntaxes in the update statement:

UPDATE table SET column = expression [, ...]    WHERE CURRENT OF cursor

Cursor indicates an open cursor.

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.