Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Delete the top 10 rows from a table using SQL Server

Tags: delete userid row
The CTE most efficient ways to Delete rows from table as per your need.

Example 1,

;WITH CTE AS
(
   SELECT TOP10*
     FROM UserDetail
)
DELETE FROM CTE


If you want to delete specific subset of rows instead of arbitrary subset, you should explicitly specify order to sub-query:

Example 2,

DELETE FROM UserDetail
WHERE Userid IN
(
  SELECT TOP 10
      UserID
  FROM [UserDetail]
  WHERE UserID =10
  ORDER BY UserID DESC
)



This post first appeared on Programming, please read the originial post: here

Share the post

Delete the top 10 rows from a table using SQL Server

×

Subscribe to Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×