Database Cleanup (SQL Server)

sql-server
Tags: #<Tag:0x00007f69fbea7e48>

#1

Good afternoon.
I have a large amount of processing and, in result, a large amount of data that need to be deleted.
Does anyone have a database cleanup script for SQL Server?

Have a nice day.


#2
TRUNCATE TABLE [HangFire].[AggregatedCounter]
TRUNCATE TABLE [HangFire].[Counter]
TRUNCATE TABLE [HangFire].[JobParameter]
TRUNCATE TABLE [HangFire].[JobQueue]
TRUNCATE TABLE [HangFire].[List]
TRUNCATE TABLE [HangFire].[State]
DELETE FROM [HangFire].[Job]
DBCC CHECKIDENT ('[HangFire].[Job]', reseed, 0)
UPDATE [HangFire].[Hash] SET Value = 1 WHERE Field = 'LastJobId'

#3

Doesnt Hangfire clean up automatically?


#4

Is it possible to add this to SQL Job?
but not for all jobs, only for Successful jobs. (I want to remove them physically)
And What do I need to do to change the above script based on that?
… One more thing, I will add Shrink Db also on the above script :slight_smile: