MS SQL Basics Tutorial: Updating data

Source: Internet
Author: User
Tags backup

11.3.1 UPDATE Syntax

The user can use the UPDATE statement to update one or more columns of data values in a table, with the following syntax:

The parameters are described as follows:

SET

The SET clause is used to specify an updated method that replaces the value of the corresponding column. If you omit the WHERE clause, all data in the table is affected. The alias of the table or column specified in the FROM clause cannot be used in the SET clause. column_name

Specifies the column for which you want to update data. The IDENTITY column cannot be updated. Expression

Can be a constant, a variable, an expression, or a subquery that returns a single value. DEFAULT

Specifies that the default value already defined is used as the value of the column. Null

Specifies that a null value is used as a column value. @variable

A predefined variable used to store the value of an expression. Note that the set @variable = Column = expression sets the variables and columns to the same value as the expression, which differs from the Set @variable = column, column = Expression statement, which assigns the value of the column to the variable before it is expressed Value to the column. The remaining parameters and considerations are the same as the DELETE statement.

11.3.2 Update Records

11.3.3 a large number of data updates

When you update data by using update, the original data that is updated is stored in the transaction log. If the table you are updating is particularly large, it is possible to fill the transaction log when the command is not finished. SQL Server then generates an error message and returns the updated data as it is. There are two ways to solve this problem: one is to increase the storage space of the transaction log, but it seems to be uneconomical; the other is to decompose the operation of the UPDATE statement and clean the transaction log in time. For example, the Update command is decomposed into two commands, in which the backup LOG command is inserted to clear the transaction log (see Chapter 15th "Backup and Recovery" for a detailed description of the BACKUP LOG command).

See the full set of "MS SQL Basics Tutorials"

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.