Solved

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

Posted on 2004-08-26
5
554 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
Comment Utility
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
Comment Utility
SET ROWCOUNT 500

DELETE FROM tblName

SET ROWCOUNT 0

this will do
0
 
LVL 3

Expert Comment

by:alexpreston
Comment Utility
Or a third method... :)

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

Expert Comment

by:sanjeev_karnik
Comment Utility
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
Comment Utility
Thank you all very much!!!!!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now