sqlserver update详细用法

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在用之前请你备份数据,在用的数据一更新错,你就挂了.

 

 

posted @ 2009-02-06 10:17  编程入门  阅读(9658)  评论(1编辑  收藏  举报