sqlserver update语句怎样更改两个数据?
2022-12-11 · 百度认证:北京惠企网络技术有限公司官方账号
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