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

前端 未结 7 995
小鲜肉
小鲜肉 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:11

    The code you tried is in fact two statements. A DELETE followed by a SELECT.

    You don't define TOP as ordered by what.

    For a specific ordering criteria deleting from a CTE or similar table expression is the most efficient way.

    ;WITH CTE AS
    (
    SELECT TOP 1000 *
    FROM [mytab]
    ORDER BY a1
    )
    DELETE FROM CTE
    
    0 讨论(0)
提交回复
热议问题