我的表(sql sever 2000)包含大量行,当我删除行时,它非常慢。
我看到一些帖子/论坛建议使用WHILE循环功能批量删除记录。
我的sql是:
DELETE FROM Tprs_master where Fincmonth='201109';
我改写为:
DELETE FROM(SELECT TOP 100 FROM tprs_master) AS t1 WHERE t1.Fincmonth='201109'
但它不起作用。
如何将上面的sql重写为DELETE TOP样式?感谢
答案 0 :(得分:5)
MSDN DELETE page提供了示例和语法
DELETE TOP (100) FROM Tprs_master where Fincmonth='201109';
注意:仅限SQL Server 2005+
另请参阅更多示例Bulk DELETE on SQL Server 2008 (Is there anything like Bulk Copy (bcp) for delete data?)
编辑:OP有SQL Server 2000
SET ROWCOUNT 100
DELETE FROM Tprs_master where Fincmonth='201109';
SET ROWCOUNT 0