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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s