sqlserver update语句怎样更改两个数据?

发布网友 发布时间:2022-04-21 05:37

我来回答

1个回答

热心网友 时间:2023-11-06 09:49

Update 语句用于修改表中的数据。

语法:

UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value

Person:

更新某一行中的一个列

我们为last name是"Rasmussen"的人添加first name:

UPDATE Person SET FirstName = 'Nina'
WHERE LastName = 'Rasmussen'

结果:

更新某一行中的若干列 我们会修改地址(address),并添加城市名称(name of the city):  UPDATE Person SET Address = 'Stien 12', City = 'Stavanger' WHERE LastName = 'Rasmussen' 结果:

方法二:

1) MySql多表更新方法:     

MySql语法:UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]     

例子:UPDATE A a , B b SET a.a1 = b.b1 , a.a2 = b.b2 WHERE a.a3 = b.b3    

2) SQLServer多表更新方法:    

SQLServer语法: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 ] ) ]   

例子:UPDATE a SET a.a1 = b.b1 , a.a2 = b.b2 FROM A a , B b WHERE a.a3 = b.b3

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com