• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 579
  • Last Modified:

All I Want To Do Is Delete The Top 500 Rows From A Table

All I Want To Do Is Delete The Top 500 Rows From A Table

I thought...
DELETE TOP 500 FROM tblName

But DELETE does not support TOP

Please help!

Cheers
Paul
0
pauljrichards
Asked:
pauljrichards
1 Solution
 
lemmeCCommented:
Try this (replace fieldname with the name of any filed from your table):

DELETE tblName
FROM (SELECT TOP 500 * FROM tblName) AS t1
WHERE tblName.fieldname = t1.fieldname




0
 
ram2098Commented:
SET ROWCOUNT 500

DELETE FROM tblName

SET ROWCOUNT 0

this will do
0
 
alexprestonCommented:
Or a third method... :)

DELETE FROM tblName WHERE idcolumn IN (SELECT TOP 500 idcolumn FROM tblName)
0
 
sanjeev_karnikCommented:
try out this way

DELETE FROM TBLNAME A WHERE EXISTS
(SELECT TOP 500 IDCOLUMN
 FROM TBLNAME
 WHERE IDCOLUMN = A.IDCOLUMN)
0
 
pauljrichardsAuthor Commented:
Thank you all very much!!!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now