如何在更改数据捕获表中创建特定列? [英] How to create particular column in a change data capture table?

查看:70
本文介绍了如何在更改数据捕获表中创建特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子 [dbo]。[CustomerDetails]



包含 Id,Name,PhoneNo,Email等栏目,地址,城市,州

i在数据库级别和表级别创建执行sp。



但是它返回

所有列:Id,姓名,电话,电子邮件,地址,城市,州

我只有在任何更新或插入或删除仅发生时才需要获取对于电子邮件和城市

如何仅提及特定栏目



在此先感谢。



我尝试了什么:



我尝试了什么:



Exec Sys.sp_cdc_enable_db

EXEC sys.sp_cdc_enable_table

@ source_schema = N'dbo',

@ source_name = N'CustomerDetail',

@ role_name = null

解决方案

在您的触发器中,将Inserted表加入CustomerDetails表并进行比较价值。如果它们不同,那么你需要做你的行动。



请注意,在列级别没有删除的概念 - 这将是对a的更新空白或空值。与插入相同。插入整行,列从null到非null值的任何移动都是更新。



这里有类似的例子 - < a href =https://www.mssqltips.com/sqlservertip/4024/sql-server-trigger-after-update-for-a-specific-value/>特定值更新后的SQL Server触发器 [ ^ ]

i have a table [dbo].[CustomerDetails]

having columns like Id, Name, PhoneNo, Email, Address, City, State
i created executed sp in db level and table level.

But its returning
All columns: Id,Name,Phone,Email,Address,City,State
I need to get only if any update or insert or delete happen only for Email and City
how to mention only particular column

Thanks in Advance.

What I have tried:

What I have tried:

Exec Sys.sp_cdc_enable_db
EXEC sys.sp_cdc_enable_table
@source_schema=N'dbo',
@source_name=N'CustomerDetail',
@role_name=null

解决方案

In your triggers join the Inserted table to your CustomerDetails table and compare the values. If they are different then you need to do your actions.

Note that there is no concept of "delete" at the column level - that would be an update to a blank or a null value. Same with insert. The entire row is inserted, any movement of the column from a null to a non-null value is an update.

There is an example of something similar here - SQL Server Trigger After Update for a Specific Value[^]


这篇关于如何在更改数据捕获表中创建特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆