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


Generating Rollback Proc with CDC


Generating Rollback Proc with CDC

Author
Message
matt6288
matt6288
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1208 Visits: 1350
Comments posted to this topic are about the item Generating Rollback Proc with CDC

I forgot to include the script to create a function that is used. So here it is:


/****** Object: UserDefinedFunction [dbo].[fn_CombiningRowsForCDC] Script Date: 10/12/2009 15:49:08 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_CombiningRowsForCDC]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fn_CombiningRowsForCDC]
GO

CREATE FUNCTION [dbo].[fn_CombiningRowsForCDC]
(
   @schema_name VARCHAR(30),
   @table_name    VARCHAR(100)
)
RETURNS VARCHAR(MAX)
AS
BEGIN
--This function is used to get a comma separated list for the script.
--Once this has been ran once you can remove it if you like.

   DECLARE @temp AS VARCHAR(MAX)
   DECLARE @cdc_object_id AS INT
   
   SELECT @cdc_object_id = CT.object_id
   FROM cdc.change_tables CT
   INNER JOIN sys.objects O ON CT.source_object_id = O.object_id
   WHERE SCHEMA_NAME(O.schema_id) = @schema_name
   AND OBJECT_NAME(O.object_id) = @table_name

   SELECT @temp = COALESCE(@temp+',','')+[column_name] FROM cdc.captured_columns CC
   WHERE object_id = @cdc_object_id

   RETURN @temp
END
GO


Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8590 Visits: 885
Thanks for the script.
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