我知道在SQL Server 2005中我们可以做类似的事情:
从tbX删除前10名,其中X = 1
在SQL2K中执行相同操作的查询是什么,考虑主键由两个FK列组成?
答案 0 :(得分:5)
SET ROWCOUNT 10
DELETE FROM tbX where X = 1
SET ROWCOUNT 0
我不会自己写这个,但是; -p
(我要去洗手......)
答案 1 :(得分:1)
这在SQL2012中适用于我:
;with window as (select top (12) * from PromoterQueue order by LogId)
delete from window
答案 2 :(得分:0)
DELETE
FROM tbX
WHERE id IN (SELECT TOP 10 id FROM tbX WHERE X = 1)
您必须先删除外键记录。
答案 3 :(得分:0)
在处理复合键时,我会像这样删除。
delete from tblX
from tblx as aa
join
(
select top 10 * from tblX
) as bb
on
aa.key1 = bb.key1
and
aa.key2 = bb.key2
答案 4 :(得分:0)
这不是正常工作的SQL,但可能会有所作为:
DELETE t
from tbx t
join (
select top 10 k1,k2 from tbx
) as t2 on t.k1 = t2.k1 and t.k2 = t2.k2
注意:如果TOP在子查询中不起作用,只需将内容插入临时表并加入。