2012-01-24 34 views
0

SSIS 2008を使用していて、挿入時にテーブルの1つの列を更新しようとしています。この1列はuniqueidentifierフィールドであり、このフィールドを更新するためのトリガーも書きました。このコードは次のとおりです。データ挿入時に自動更新をトリガーする方法は?

CREATE TABLE dbo.rd_information3_cleaned (
c1 uniqueidentifier NULL, 
    c2 nvarchar(50), 
    c3 nvarchar(50), 
c4 nvarchar(50) 
) 

create trigger dbo.trg_client_information_id 
on client_information 
after insert 
as 
begin 
    update client_information 
    set client_information_id = newid() 
     from Inserted 
end 

私はこのコードが動作することを知っています。私はSSMSでテストし、この列を更新します。また、私のテーブルには、次のようになります。

c1        c2 c3 c4 
xxxx-xxxx-xxxx-xxxx A BB C5 
xxxx-xxxx-xxxx-xxxx A2 BB C 
xxxx-xxxx-xxxx-xxxx A3 BB C7 
xxxx-xxxx-xxxx-xxxx A4 BB C 

しかし、私は、このSSISパッケージを実行しようとすると、私はC2への書き込み - トリガが列「C1」を更新する必要があるため、C4。しかし、代わりにエラーが発生しています:

Information: 0x40043007 at Write to Client_Information, SSIS.Pipeline: Pre-Execute phase is beginning. 
Information: 0x4004300C at Write to Client_Information, SSIS.Pipeline: Execute phase is beginning. 
Error: 0xC0202009 at Write to Client_Information, Client_Information [27]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. 
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "The statement has been terminated.". 
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Cannot insert duplicate key row in object 'dbo.Client_Information' with unique index 'IX_Client_Demographics_Unique'.". 
Error: 0xC0209029 at Write to Client_Information, Client_Information [27]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "OLE DB Destination Input" (40)" failed because error code 0xC020907B occurred, and the error row disposition on "input "OLE DB Destination Input" (40)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure. 
Error: 0xC0047022 at Write to Client_Information, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Client_Information" (27) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (40). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure. 
Information: 0x40043008 at Write to Client_Information, SSIS.Pipeline: Post Execute phase is beginning. 
Information: 0x402090DF at Write to Client_Information, Client_Information [27]: The final commit for the data insertion in "component "Client_Information" (27)" has started. 
Information: 0x402090E0 at Write to Client_Information, Client_Information [27]: The final commit for the data insertion in "component "Client_Information" (27)" has ended. 
Information: 0x4004300B at Write to Client_Information, SSIS.Pipeline: "component "Client_Information" (27)" wrote 2 rows. 
Information: 0x40043009 at Write to Client_Information, SSIS.Pipeline: Cleanup phase is beginning. 
Task failed: Write to Client_Information 
SSIS package "Echo Information Migration2.dtsx" finished: Success. 
The program '[2564] Echo Information Migration2.dtsx: DTS' has exited with code 0 (0x0). 

このエラーの原因は、client_information_idフィールドです。私はそのフィールドをuniqueidentifierにするだけで、SSMSに複数の行を書くことができます。それ以外の場合は、このテーブルに複数の行を書き込むことはできません。だから私は不思議です。トリガーに十分な時間を与えるためにSSISでTIMEプロパティーを設定する必要がありますか?なぜこのエラーが発生するのでしょうか?

また、OLE DB宛先を編集し、最大挿入コミットサイズ= 1を設定しましたが、同じエラーが発生しました。

答えて

1

ストーリーは短いので、トリガーは使用しないでください。documentationに示すようにDEFAULTを使用してください。あなたが掲示テーブルDDLトリガコードはお互いに何の関係もないように見えるが、私は本当にこのような何かをしたいと仮定します。

create table dbo.Clients (
    ClientID uniqueidentifier not null primary key default newid(), 
    ClientAttributeA nvarchar(50) not null, 
    -- etc. 
) 

私はあなたがSSMSで試験した場合、あなたがAに1行を挿入するテストと思われますSSISパッケージは複数の行を挿入しています。 NEWID()関数はトリガーで1回だけ呼び出されるので、1行挿入すると動作しますが、複数の行を挿入するとそれぞれのNEWID()値が同じになり、重複したキー違反が発生します。

関連する問題