Skenario :
Anda bekerja sebagai SQL Server DBA atau pengembang, Anda baru saja mengaktifkan Ubah Pengambilan Data di salah satu database. Periode retensi default adalah 3 hari. Anda ingin mengubah periode retensi menjadi 1000 hari. Bagaimana Anda melakukannya?
Solusi:
Skrip di bawah ini dapat digunakan untuk mengubah periode retensi untuk Change Data Capture ( CDC) di database SQL Server.
/*---------------------------------------
Change CDC Retention Period
The retention is provide in minutes , If we are providing in Days then we
have to convert that to minutes.
-----------------------------------------*/
USE [DatabaseName]
GO
DECLARE @Retention_IN_DAYS INT
DECLARE @Retention_IN_Minutes INT
SET @Retention_IN_DAYS=10--> Provide the Retention period in days here
SET @Retention_IN_Minutes=@Retention_IN_DAYS * 24 * 60
--Print Current Retention Period
SELECT retention / 60 / 24 AS [Retention_In_Days]
FROM msdb.dbo.cdc_jobs
WHERE job_type = 'cleanup'
--SET Retention to Required Days
EXECUTE sys.sp_cdc_change_job
N'cleanup',
@retention = @Retention_IN_Minutes
--Check if Retention is Set for Given Days
SELECT retention / 60 / 24 AS [Retention_In_Days]
FROM msdb.dbo.cdc_jobs
WHERE job_type = 'cleanup'