?
Solved

SQL Status statement

Posted on 2011-04-19
2
Medium Priority
?
348 Views
Last Modified: 2012-05-11
I am using the following query to delete a really large colelction of logs. I would like to chnge teh simple pint statement to increase with each cycle.

I.E.

1,000 rows deleted....
2,000 rows deleted...

while exists(select count(1) from <table> where LogDate <=getdate()-1)
begin
  set rowcount 1000
  delete from <table> where LogDate <=getdate()-1
  print '1,000 rows deleted'
  waitfor delay '00:00:01'
end
0
Comment
Question by:Frias-JH
2 Comments
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 500 total points
ID: 35426647
try
declare @RowsDeleted bigint
set @RowsDeleted = 0
while exists(select count(1) from <table> where LogDate <=getdate()-1)
begin
  set rowcount 1000
  delete from <table> where LogDate <=getdate()-1
  set @RowsDeleted = @RowsDeleted + 1000
  print cast(@RowsDeleted as varchar) + ' rows deleted'
  waitfor delay '00:00:01'
end

Open in new window

0
 
LVL 22

Accepted Solution

by:
Nico Bontenbal earned 500 total points
ID: 35426685

declare @count int = 1
while exists(select count(1) from <table> where LogDate <=getdate()-1)
begin
  set rowcount 1000
  delete from <table> where LogDate <=getdate()-1
  print convert(varchar,@count * 1000) + ' rows deleted'
  set @count  = @count  + 1
  waitfor delay '00:00:01'
end

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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 to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

850 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