スペースを考慮する場合は、CDCテーブルをいつでも割り当てて、別のサーバーに存在する可能性のある別のファイルグループで作業することができます。あなたはこのようにそれをするでしょう:
ALTER DATABASE YourDatabase
ADD FILEGROUP [cdc_ChangeTables];
go
--this step requires going on to somewhere on your hard drive and creating a folder
ALTER DATABASE YourDatabase
ADD FILE ( NAME = N'cdc_ChangeTables',
FILENAME = N'E:\NameOfFolderYouSetUp\YourDatabase_cdc_ChangeTables.mdf',
SIZE = 1048576KB,
FILEGROWTH = 102400KB )
TO FILEGROUP [cdc_ChangeTables];
GO
次に、CDCテーブルを設定する場合は、代わりにそのファイルグループに向けます。
EXEC sys.sp_cdc_enable_table
@source_schema = N'dbo',
@source_name = N'TableYouWantToCapture',
@role_name = N'cdc_admin',
@filegroup_name = N'cdc_ChangeTables', --this is where you name the filegroup from previous step
@supports_net_changes = 1,
@capture_instance = N'dbo_TableYouWantToCapture',
@captured_column_list = 'ColumnName1, ColumnName2'; --comma-delimited list of column names
GO
更新/削除のみを照会する場合は、次のようなシステム関数を使用できます。
SELECT *
FROM cdc.fn_cdc_get_all_changes_dbo_TableYouWantToCapture(@from_lsn, @to_lsn, N'all update old')
WHERE __$operation IN (1,3,4)