Saturday, 3 October 2015

delete top N rows mssql

Leave a Comment
This example show how to delete top N rows in mssql, where N is dynamic number. It could be 1000, 100, or 10 .

  ;WITH CTE AS  
 (  
 SELECT TOP 1000 *  
 FROM [table_name]  
 ORDER BY a1  
 )  
 DELETE FROM CTE  


  • 1000 is the example number.
  • [table_name] is the table you want to delete
  • a1 is just a example of sort by column a1
Tanks to stack overflow for this help :

http://stackoverflow.com/questions/8955897/how-to-delete-the-top-1000-rows-from-a-table-using-sql-server-2008


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.