2
Reply

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

Aryan Kumar

Aryan Kumar

2y
10.3k
0
Reply

Please provide brief explanation with query.

    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. )

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