sqlserver update詳細用法

來源:互聯網
上載者:User

UPDATE是我們常SQL語句之一,update主要用於更改表中的現有資料.

更新一個表:update product set l_parentid ='1'

詳細解說: update 表名 set 列名 =參數

更新兩個表或多個表: update product set l_parentid = producttype.parentid from product,producttype where product.l_typeid =producttype.id

詳細解說:  update 表名 set 列名 =參數 from 表名1,表名2 where 指定條件

 

UPDATE詳細文法
        {
         table_name WITH ( < table_hint_limited > [ ...n ] )
         | view_name
    
    | rowset_function_limited
        }
        SET
        { column_name = { expression | DEFAULT | NULL }
        | @variable = expression
        | @variable = column = expression } [ ,...n ]

    { { [ FROM { < table_source > } [ ,...n ] ]

        [ WHERE
            < search_condition > ] }
        |
        [ WHERE CURRENT OF
        { { [ GLOBAL ] cursor_name } | cursor_variable_name }
        ] }
        [ OPTION ( < query_hint > [ ,...n ] ) ]

< table_source > ::=
    table_name [ [ AS ] table_alias ] [ WITH ( < table_hint > [ ,...n ] ) ]
    | view_name [ [ AS ] table_alias ]

    | rowset_function [ [ AS ] table_alias ]
    | derived_table [ AS ] table_alias [ ( column_alias [ ,...n ] ) ]
    | < joined_table >

< joined_table > ::=
    < table_source > < join_type > < table_source > ON < search_condition >
    | < table_source > CROSS JOIN < table_source >
    | < joined_table >

< join_type > ::=
    [ INNER | { { LEFT | RIGHT | FULL } [OUTER] } ]
    [ < join_hint > ]
    JOIN

< table_hint_limited > ::=
    
{    FASTFIRSTROW
        | HOLDLOCK
        | PAGLOCK
        | READCOMMITTED
        | REPEATABLEREAD
        | ROWLOCK
        | SERIALIZABLE
        | TABLOCK
        | TABLOCKX
        | UPDLOCK
    }

< table_hint > ::=
    
{    INDEX ( index_val [ ,...n ] )
        | FASTFIRSTROW
        | HOLDLOCK
        | NOLOCK
        | PAGLOCK
        | READCOMMITTED
        | READPAST
        | READUNCOMMITTED
        | REPEATABLEREAD
        | ROWLOCK
        | SERIALIZABLE
        | TABLOCK
        | TABLOCKX
        | UPDLOCK
    }

< query_hint > ::=
    {    { HASH | ORDER } GROUP
        | { CONCAT | HASH | MERGE } UNION
        | {LOOP | MERGE | HASH } JOIN
        | FAST number_rows
        | FORCE ORDER
        | MAXDOP
        | ROBUST PLAN
        | KEEP PLAN
    }

 

參數

table_name

需要更新的表的名稱。如果該表不在當前伺服器或資料庫中,或不為目前使用者所有,這個名稱可用連結的伺服器、資料庫和所有者名稱來限定。

SET

指定要更新的列或變數名稱的列表。

小貼士:SQL Server 聯機叢書就提供了很詳細Transact-SQL 參考

update在用之前請你備份資料,在用的資料一更新錯,你就掛了.

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.