链接服务器表的SQL更新会触发每个受影响的行的触发器

时间:2017-01-23 16:17:50

标签: sql sql-server database triggers

我正在查看链接数据库服务器的一些奇怪行为。我只是创建一个临时表变量,添加一些键,这些键可以在链接服务器表中找到,并使用它与目标表连接以进行更新。

declare  @stats_table table
(
    [Index]     [bigint]            not null primary key
)

insert into @stats_table ([Index] )
select 1 union all
select 2 union all
select 3 union all
select 4

update  [source]
set     [source].[STATUS] = (-1)

from    @stats_table as [stats]

    inner join [LINKED INSTANCE].[DATABASE].[dbo].[LINKEDTABLE] as [source]
    on [source].[INDEX] = [stats].[Index] 

这导致远程端(目标)上的触发器每行更新一次,而不是在语句级别触发。在上面的示例中,触发器触发4次,但下面的语句仅触发一次。

update  [source]
set     [source].[STATUS] = (-1)

from    [LINKED INSTANCE].[DATABASE].[dbo].[LINKEDTABLE] as [source]
where [source].[INDEX] in(1, 2, 3, 4)

有没有人能够解释我出错的地方。是否有配置设置或我遗漏的东西?

此致

0 个答案:

没有答案