-- ===
-- Step 0: Enable Db for CDC
-- ===

-- Enable Db for CDC
EXEC sys.sp_cdc_enable_db
GO

-- ===
-- Step 1: Startup Debezium
-- ===



-- ===
-- Step 2: Then enable a table for CDC
-- ===

-- Create new table
CREATE TABLE dbo.MyNewTable(
	id int not null primary key ,
	firstname nvarchar (50) null
);

-- Insert record
insert into dbo.MyNewTable (id, firstname) values (1, 'AAA');
insert into dbo.MyNewTable (id, firstname) values (2, 'BBB');



-- Enable 
EXEC sys.sp_cdc_enable_table  
@source_schema = N'dbo',  
@source_name   = N'MyNewTable',  
@role_name     = null, 
@supports_net_changes = 0	-- no need to put it to 1, because Debezium use the all_changes function, not the net_changes one. 
							-- see: SqlServerConnection.java (line 57) >     private static final String GET_ALL_CHANGES_FOR_TABLE = "SELECT * FROM cdc.[fn_cdc_get_all_changes_#](ISNULL(?,sys.fn_cdc_get_min_lsn('#')), ?, N'all update old')";
GO  

/*
* Here, the snapshot is not performed.
*/


-- ===
-- Step 3: Make a small change
-- ===

insert into dbo.MyNewTable (id, firstname) values (3, 'CCC');

/*
* Only that row appears in DBZ.Just the new changes appears, no snapshot is performed.
*/