SQL Server series: UPDATE statement

Source: Internet
Author: User

The UPDATE statement is used to update the existing data with the update syntax:

[With <common_table_expression> [... n] ]UPDATE     [TOP (expression) [PERCENT]] {{Table_alias| <Object> |rowset_function_limited[With (<Table_Hint_Limited> [... n] ) ]      }      | @table_variable        }    SET{column_name={Expression| DEFAULT | NULL }          |{Udt_column_name. {{Property_name=expression|Field_name=expression}|Method_name (argument[,... N] )                              }          }          |column_name {. WRITE (expression,@Offset,@Length ) }          | @variable =expression| @variable = column =expression|column_name {+= | -= | *= | /= | %= | &= | ^= | |=} expression| @variable{+= | -= | *= | /= | %= | &= | ^= | |=} expression| @variable = column{+= | -= | *= | /= | %= | &= | ^= | |=} expression}[,... N]     [<output clause>]    [from{<table_source>} [,... n] ]     [WHERE {<search_condition> | {[Current of {{[GLOBAL]cursor_name}|Cursor_variable_name}] }            }     ]     [OPTION (<query_hint> [,... n] ) ][ ; ]<Object>::={     [server_name. database_name. schema_name. | database_name. [Schema_name] . |schema_name. ] Table_or_view_name}

1. Update the entire column

UPDATE [dbo]. [Product] SET [createdate] = GETDATE ()

2. Specify calculated values

UPDATE [dbo]. [Product] SET [unitprice] = [unitprice] * 2

3. Updating with default values

The default value for column CreateDate is set to GETDATE (), and the default value is null if not set.

UPDATE [dbo]. [Product] SET [createdate] = DEFAULT

4. Where condition limits update multi-column fields

UPDATE [dbo].[Product]SET [ProductName] = 'LINQ to SQL',[UnitPrice] =  -,[CreateDate] = GETDATE()WHERE [ProductID] = 1

5. References

Http://msdn.microsoft.com/zh-cn/library/ms177523.aspx

SQL Server series: UPDATE statement

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.