Solved

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

Posted on 2004-08-26
5
572 Views
Last Modified: 2010-08-05
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
Comment
Question by:pauljrichards
5 Comments
 
LVL 5

Accepted Solution

by:
lemmeC earned 500 total points
ID: 11901223
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
 
LVL 11

Expert Comment

by:ram2098
ID: 11901297
SET ROWCOUNT 500

DELETE FROM tblName

SET ROWCOUNT 0

this will do
0
 
LVL 3

Expert Comment

by:alexpreston
ID: 11901379
Or a third method... :)

DELETE FROM tblName WHERE idcolumn IN (SELECT TOP 500 idcolumn FROM tblName)
0
 
LVL 1

Expert Comment

by:sanjeev_karnik
ID: 11901525
try out this way

DELETE FROM TBLNAME A WHERE EXISTS
(SELECT TOP 500 IDCOLUMN
 FROM TBLNAME
 WHERE IDCOLUMN = A.IDCOLUMN)
0
 

Author Comment

by:pauljrichards
ID: 11902093
Thank you all very much!!!!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question