Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sys.sp_cdc_enable_table does not consider additions or removal of columsn to the table


sys.sp_cdc_enable_table does not consider additions or removal of columsn to the table

Author
Message
ramdas.subramanian
ramdas.subramanian
SSC-Enthusiastic
SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)

Group: General Forum Members
Points: 134 Visits: 63
I am building a CDC on my tables. However, I noticed, if I add a new column to the table being audited, the Audit table doesnot have this column. Instead, the only way I can see is to disable the CDC on the table and re-enable it, which menas the data sitting in the audit table is Lost.

Is there any way this can be done seamlessly in CDC?

--EXEC sys.sp_cdc_enable_db
--EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'AuditTest', @role_name = NULL

/*
Operation 1 = Delete
Operation 2 = Insert
Operation 3 = Old value before the operation
Operation 3 = New Value after the Operation
*/

CREATE TABLE dbo.AuditTest(RowID INT IDENTITY(1,1),VALUE VARCHAR(50),UserName VARCHAR(50), CreationDate DATETIME DEFAULT GETDATE(),ModifiedDate DATETIME)

EXEC sys.sp_cdc_enable_table @source_schema = 'dbo', -- sysname
@source_name = 'AuditTest', -- sysname
@capture_instance = NULL, -- sysname
@role_name = NULL -- sysname


INSERT INTO dbo.AuditTest
( VALUE ,UserName )
VALUES ( 'QQQ' ,'User123' )

-------THIS NEW COLUMN ADDED IS NOT AVAILABLE IN "dbo_AuditTest_CT"--------
ALTER TABLE AuditTest add TESTCol varchar(10)

UPDATE AuditTest SET Value='TESTINGzzz' WHERE Value='QQQ'

DELETE from AuditTest

select CASE
WHEN [__$operation]=1 THEN 'DELETE'
WHEN [__$operation]=2 THEN 'INSERT'
WHEN [__$operation]=3 THEN 'OLD VALUE'
WHEN [__$operation]=4 THEN 'NEW VALUE'
END AS OPERATION
,*
from cdc.dbo_AuditTest_CT



Also, what are the other ways we can Audit transactional changes to the tables?

Cheers
Ram
ramdas.subramanian
ramdas.subramanian
SSC-Enthusiastic
SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)

Group: General Forum Members
Points: 134 Visits: 63
bump
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search