日期:2014-05-18 浏览次数:20587 次
use test go SET NOCOUNT ON if OBJECT_ID('dbo.tb_A','U') is not null drop table dbo.tb_A create table dbo.tb_A ( id int not null ); GO if OBJECT_ID('dbo.tb_B','U') is not null drop table dbo.tb_B create table dbo.tb_B ( id int not null ); GO INSERT INTO dbo.tb_A SELECT 1 UNION ALL SELECT 2 ; GO SELECT * FROM dbo.tb_A; GO DELETE FROM dbo.tb_A OUTPUT deleted.* INTO dbo.tb_B WHERE id = 1; GO SELECT * FROM dbo.tb_A; SELECT * FROM dbo.tb_B;
------解决方案--------------------
create table #t1(col1 varchar(10),col2 varchar(10),col3 varchar(10))
create table #t2(col1 varchar(10),col2 varchar(10),col3 varchar(10))
while exists(select top 1 0 From #t1)
begin
delete top (100) from #t1 output deleted.* into #t2
waitfor delay '00:00:00:300'
end
--用循环处理