Aryan Kumar
How To Delete First Or Last 1000 Rows In SQL-SERVER ?

Please provide brief explanation with query.

By Aryan Kumar in SQL Server on Aug 05 2022
  • Tuhin Paul
    Apr, 2023 23

    To delete the first 1000 rows:

    DELETE TOP(1000) FROM TableName

    To delete the last 1000 rows:

    1. DELETE FROM TableName WHERE PrimaryKeyColumn IN (
    2. SELECT TOP(1000) PrimaryKeyColumn FROM TableName ORDER BY PrimaryKeyColumn DESC
    3. )

    • 1
  • pankaj kumar
    Oct, 2022 18

    Delete FROM Customers where CustomerID = (select max(CustomerID) from Customers) or CustomerID = (select min(CustomerID) from Customers);

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS