/**********************************************/
Delete Script - To delete records from large History tables
/**********************************************/
It is many times required to delete records from History tables which stay in database unattended.
When you try to delete specific set of records or even one record, the Management console hangs. Here is how you can delete required records easily.
Table : masDispatchHistory
Identity Column : iDispatchHistory
/**********************************************/
--Select Count(1) from masDispatchHistory
Declare @i bigint, @max bigint
Select @i=min(iDispatchHistory),@max = max(iDispatchHistory) from masDispatchHistory
Print @i
Print @max
--set @i = 4760077 -- Set this value here in case you want to start from a known value and avoid extra loops
While (@i < @max)
Begin
Print @i
delete from [dbo].masDispatchHistory where iDispatchHistory < @i
set @i = @i+1000
Waitfor delay '00:00:01:000' -- Wait so that SQL gives time for other internal processes to run and execute. This will not hang your system
End
-- Do comment if you need any help.
Delete Script - To delete records from large History tables
/**********************************************/
It is many times required to delete records from History tables which stay in database unattended.
When you try to delete specific set of records or even one record, the Management console hangs. Here is how you can delete required records easily.
Table : masDispatchHistory
Identity Column : iDispatchHistory
/**********************************************/
--Select Count(1) from masDispatchHistory
Declare @i bigint, @max bigint
Select @i=min(iDispatchHistory),@max = max(iDispatchHistory) from masDispatchHistory
Print @i
Print @max
--set @i = 4760077 -- Set this value here in case you want to start from a known value and avoid extra loops
While (@i < @max)
Begin
Print @i
delete from [dbo].masDispatchHistory where iDispatchHistory < @i
set @i = @i+1000
Waitfor delay '00:00:01:000' -- Wait so that SQL gives time for other internal processes to run and execute. This will not hang your system
End
-- Do comment if you need any help.