Tag Archives: limit rows

Deleting a limited amount off records in MSSQL

It’s been awhile since I’ve done it and today had a need for it. Kept getting “incorrect syntax near 5”

I got bit by the fact that parens are needed around the number value.

So what a person needs to do is:
    DELETE TOP (5) FROM YourTableName

Make sure you put an appropriate ORDER BY on your sql statement and also wrap it in a transaction as to not delete haphazardly without verifying.

Advertisements