大家好,假设我有表中有 两个字段 id,seq,context,id和seq为主键,
如果现在的值为:
id seq context
1 1 test1
1 2 test2
现在我想改成
id seq context
1 2 test1
1 1 test2
请问这sql语句怎么写
用触发器。
create trigger t1
on tb
for update
as
begin
update tb
set seq=deleted.seq
from tb join deleted on tb.id=deleted.id and seq!=deleted.seq
end
然后执行
update tb
set seq=(select seq from tb where id=1 and seq=2)
这么一个思路,未经测试
select * into #temp from table
--update #temp set content=''
update table set content=(select top 1 content from #temp where id=1 and seq=2) where id=1 and seq=1
update table set content=(select top 1 content from #temp where id=1 and seq=1) where id=1 and seq=2
drop table #temp