sqlserver update语句怎样更改两个数据?
create table student(id int,name varchar(20),grade int)
insert into student values(1,null,null)
update student set name='hehe',grade=1 where id=1
应该能看懂吧,希望对你有所帮助
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