我有以下查询,一次提供10条记录,我想将数据保存到另一个表中,该怎么做?
DELETE FROM TestQueue WITH (READPAST) OUTPUT DELETED.*
WHERE TestQueue.Id IN
(
SELECT TOP(10) Id -- maximum batch size
FROM TestQueue
WHERE Data >= 0 AND Data <= 1000 -- selection criteria
ORDER BY Id ASC
)
答案 0 :(得分:0)
以下是步骤。
创建一个包含所需列的输出表
CREATE TABLE dbo.t_audit (Id int not null);
使用OUTPUT子句,选择您想要保留的所需值。
DELETE FROM TestQueue WITH (READPAST)
OUTPUT DELETED.ID INTO t_audit
WHERE TestQueue.Id IN (SELECT TOP(10) Id -- maximum batch size
FROM TestQueue
WHERE Data >= 0 AND Data <= 1000 -- selection criteria
ORDER BY Id ASC)