logit99 发表于 2010-04-14 10:57

bcp in 到底会不会触发触发器?

一直认为bcp in 是不会触发触发器的,不管是慢速还是快速bcp。但有人跟我争,说表上有索引且有触发器的情况下,会触发触发器。被搞糊涂了,请问到底是怎么样的?

andkylee 发表于 2010-04-14 11:32

会,不信自己试一下!

wfcjz 发表于 2010-04-14 14:14

bcp IN之前,最好把触发器及索引删了,导入完成后重建,这样做一是保证BCP导入速度,二是为了数据安全!

hobbylu 发表于 2010-04-14 15:06

会触发的

D_D_D_D 发表于 2010-04-15 11:03

bcp does not fire any trigger that exists on the target table.

这个是手册上的原话

试验过,肯定不会触发trigger。

andkylee 发表于 2010-04-15 13:56

回复 5# D_D_D_D


    哪儿看到的?请贴出详细的原文来。 并标记出来源!

hobbylu 发表于 2010-04-15 14:36

呵呵,看到5楼的兄弟回答,我去查找了一下手册,手册上确实有说不会引起触发器,不过这个是在15.0版本之后,之前的版本是会的。原文我给大家引用一下,仅供大家参考。
These are situations in which Adaptive Server version 15.0.2 uses fast bcp but earlier versions Adaptive Server used slow bcp (in all cases sp_dboption ‘select into/bulkcopy/pllsort’ is enabled and the table does not have a clustered index):

When the table has a non-unique, nonclustered index. Adaptive Server logs the index updates and the page allocations only. It does not log inserts into the table.

When a table has triggers. However, bcp does not fire any triggers in the target table.

When a table has datarows or datapage locking scheme with a clustered index.


12.5.2的Utility Guide中指出
bcp clarification
In the section “bcp modes” in Chapter 3, “Using bcp to Transfer Data to and from Adaptive Server” in the Utility Guide, the definitions of bcp in were reversed and incorrectly stated as:

bcp in works in one of two modes:

Fast bcp – logs each row insert that it makes, used for tables that have one or more indexes or triggers.

Slow bcp – logs only page allocations, copying data into tables without indexes or triggers at the fastest speed possible.

The correct definitions are as follows:

bcp in works in one of two modes:

Slow bcp – logs each row insert that it makes, used for tables that have one or more indexes or triggers.

Fast bcp – logs only page allocations, copying data into tables without indexes or triggers at the fastest speed possible.


在15.0.3手册中又指出
Adaptive Server Enterprise 15.0.3 > Adaptive Server Enterprise Cluster Edition 15.0.3 Clusters Users Guide > System Changes > Utilities > Changes to utility programs


Chapter 15: System Changes
--------------------------------------------------------------------------------

bcp
Versions earlier than 15.0.3 did not allow you to run fast bcp on tables with non-clustered indexes or triggers. Cluster Edition version 15.0.3 and later removes this restriction. See the Utility Guide.

D_D_D_D 发表于 2010-04-15 16:20

大家再试试吧,我刚试完了,确实不会触发触发器。有索引,有视图,有insert,update,delete的trigger

而且版主贴的文章应该是描述快速bcp和慢速bcp的,而不是说bcp时会不会cause trigger tofire。

只要表上有触发器或索引之一,就是慢速bcp,没有索引和触发器,就是快速。

祝福自己 发表于 2010-04-27 18:10

:dizzy::em03::sleepy:

祝福自己 发表于 2010-04-27 18:11

:oops::em18::wink:
页: [1] 2
查看完整版本: bcp in 到底会不会触发触发器?