34,594
社区成员
发帖
与我相关
我的任务
分享
--这个表应该有主键吧?
--先把数据取出来放到临时表里
select top 100 * into #temp from SUMBMIT
--然后更新数据
update SUMBMIT set SendFlag=1 from #temp where SUMBMIT.主键=#temp.主键
--再把数据从临时表取出来。
select * from #temp
--删掉临时表
drop table #temp
UPDATE SUMBMIT SET SENDFLAG=1 WHERE ID IN (SELECT TOP 100 ID FROM SUMBMIT ORDER BY ID)
??set nocount on
use tempdb
go
if (object_id ('tb' ) is not null )
drop table tb
go
create table tb (id int identity (1 , 1 ), name varchar (10 ), tag int default 0 )
insert into tb (name ) select 'a'
insert into tb (name ) select 'b'
insert into tb (name ) select 'c'
insert into tb (name ) select 'd'
insert into tb (name ) select 'e'
go
update top (2 ) tb with (rowlock , readpast ) set tag = 1 output inserted . id , inserted . name where tag = 0
go
update top (2 ) tb with (rowlock , readpast ) set tag = 1 output inserted . id , inserted . name where tag = 0
go
update top (2 ) tb with (rowlock , readpast ) set tag = 1 output inserted . id , inserted . name where tag = 0
go
set nocount off
/*
id name
----------- ----------
1 a
2 b
id name
----------- ----------
3 c
4 d
id name
----------- ----------
5 e
*/
select top 100 * into # from sumbmit
update a set a.sendflag=1 from sumbmit join # on a.字段=b.字段
drop table #