declare @tb table (col1 int)insert @tb select '1'
union all
select '2'
union all
select '3'这张表 @tb
有没有办法在不创建另外的表的情况下给他重新赋值?就好像给变量赋值一样
union all
select '2'
union all
select '3'这张表 @tb
有没有办法在不创建另外的表的情况下给他重新赋值?就好像给变量赋值一样
declare @tb table (col1 int)
insert @tb select '1'
union all
select '2'
union all
select '3'
update @tb set col1=10
where col1=3
col1
1
2
3
现在我想把它变成 成col1
4
5
6但是不能另外在定义一个表
union all
select '2'
union all
select '3'update @tb
set col1=col1+3select * from @tb
(3 行受影响)(3 行受影响)
col1
-----------
4
5
6(3 行受影响)
insert @tb select '1'
union all
select '2'
union all
select '3'
declare @i int
set @i=3
update @tb set col1=@i,@i=@i+1
select * from @tb
/*
col1
-----------
4
5
6(3 個資料列受到影響)
*/
就是update语句的。恩。就这样