发布网友 发布时间: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