MSSQL UPDATE
来源:互联网 发布:python廖海峰 编辑:程序博客网 时间:2024/06/05 15:29
Here is how to do an update from in SQL Server. I am posting this because I always forget the syntax and I put the from after the update and before the set when really it should be the other way around.
Anyway this is useful for moving values from one table to another. I used to write cursors and things like that to accomplish the same thing when I didn't know about update from. This is much easier than writing a loop for simple updates.
Anyway this is useful for moving values from one table to another. I used to write cursors and things like that to accomplish the same thing when I didn't know about update from. This is much easier than writing a loop for simple updates.
declare @table1 table(ID int, Value varchar(25))
declare @table2 table(ID int, Value varchar(25))
insert into @table1 values(1, null)
insert into @table1 values(2, null)
insert into @table1 values(3, null)
insert into @table2 values(1, 'test1')
insert into @table2 values(2, 'test2')
insert into @table2 values(3, 'test3')
select * from @table1
select * from @table2
update t1
set t1.Value = t2.value
from @table1 as t1 inner join @table2 as t2 on t1.ID = t2.ID
select * from @table1
Here are the results of the above script:
--Table 1 Before
ID Value
----------- -------------------------
1 NULL
2 NULL
3 NULL
--Table 2 Before
ID Value
----------- -------------------------
1 test1
2 test2
3 test3
--Table 1 After
ID Value
----------- -------------------------
1 test1
2 test2
3 test3
- MSSQL UPDATE
- mssql update 的用法
- mssql update 的用法
- mssql update error
- mssql update 的用法
- UPDATE 语句 ORACLE /MSSQL 对比
- Mssql触发器学习例子之UPDATE触发器
- 多表联合update[mysql/mssql]
- mssql存储过程-动态更新update
- 关于Oracle的UPdate与 MSSQL的不同
- oracle与mssql语法差异 2.update from
- mssql
- mssql
- MSSQL
- MSSQL
- MSSQL
- MSSQL
- MSSQL
- IBM将派毛新生等专家出席CCSE2008并作演讲报告
- 真正的朋友与普通的朋友的区别 (转)
- C++ 对象的内存布局(上)
- 最让人感动的文章
- 什么是朋友 (转)
- MSSQL UPDATE
- 关于浮点数的精度与取值范围的问题
- mips汇编语言伪指令
- struts2
- C++ 对象的内存布局(下)
- C++ 异 常 处 理
- 关于Tomcat中配置https协议(使用axis容器)
- C++ 虚函数表解析
- 生命中仅有三种感情你拥有吗 (转)