How to delete the top 1000 rows from a table using Sql Server 2008?

前端 未结 7 1027
小鲜肉
小鲜肉 2020-12-01 02:34

I have a table in SQL Server. I would like to delete the top 1000 rows from it. However, I tried this, but I instead of just deleting the top 1000 rows it deleted all the

7条回答
  •  眼角桃花
    2020-12-01 03:02

    It is fast. Try it:

    DELETE FROM YourTABLE
    FROM (SELECT TOP XX PK FROM YourTABLE) tbl
    WHERE YourTABLE.PK = tbl.PK
    

    Replace YourTABLE by table name, XX by a number, for example 1000, pk is the name of the primary key field of your table.

提交回复
热议问题