November 11, 2009 at 3:19 am
Hi all,
I need to create a stored procedure that will delete 10,000 rows regularly; can anyone let me know how I would be able to do this please?
Thank you in advance.
November 11, 2009 at 3:28 am
Ummm, you have given no details so this is a complete guess
Create procedure DeleteProc
as
Delete top 10000
from <yourtable>
go
And create a job to execute it in sqlagent
November 11, 2009 at 3:36 am
Dave Ballantyne (11/11/2009)
Ummm, you have given no details so this is a complete guess
Create procedure DeleteProc
as
Delete top 10000
from <yourtable>
go
And create a job to execute it in sqlagent
Just a small syntax correction – The number 10000 should be in parentheses
Create procedure DeleteProc
as
Delete top (10000)
from <Yourtable>
go
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
November 11, 2009 at 3:41 am
Thats a habit im trying to pick up , but obviously failing 🙂
November 11, 2009 at 3:50 am
Thank you for the reply, sorry I was not clear on my post, I have over 300000 rows in a table and I need to delete most of the rows but I need to leave some rows for testing purpose. Is there a way to create a loop to regularly to delete the 30000 rows or 10000 rows at a time?
November 11, 2009 at 4:04 am
You can have a delete statement that is using top in it as Dave Ballantyne showed you. Then you can run it in a loop. Here is one way of doing it in a loop that runs 10 times:
Delete top (30000) from <Yourtable>
Go 10
If you need something else, please explain what you need.
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply