SQL收集

来源:互联网 发布:mac office软件 编辑:程序博客网 时间:2024/04/28 21:42

以下所有来自转载

1.如何UPDATE两条完全相同的记录其中的一条

create table test_top(id int, name varchar(10))
insert into test_top
select '1','aa' union all
select '1','aa'
1种
set rowcount 1
update test_top set name='tt'
set rowcount 0

2种
;
with ttttt as
(
   
select * , row = row_number() over (order by id ) from test_top
)
update ttttt set name='x' where row =1