简体   繁体   English

跨数据库SQL触发器史诗失败

[英]Cross DB SQL Trigger Epic Failure

I have the below SQL Trigger on a SQL 2005 box that is supposed to help me replicate certain Person Info to another database to be used for Reporting and various other things as a reference. 我在SQL 2005框上有下面的SQL触发器,该触发器帮助我将某些“人员信息”复制到另一个数据库中,以用于报表和其他各种参考。

I have 1 DB named Connect which is where the current app manipulates the Person Data on tblPerson. 我有1个名为Connect的数据库,这是当前应用程序在tblPerson上处理人员数据的地方。 I have another DB, on same physical box, named MATRIX where a new app manipulates it's Data. 我在同一物理框中有另一个数据库,名为MATRIX,新应用在其中操纵数据。 I am trying to build a Table in MATRIX called tblIdentificationMap that simply stores all of the various ID's we have from the different apps in house. 我正在尝试在MATRIX中构建一个名为tblIdentificationMap的表,该表仅存储我们内部来自不同应用程序的所有各种ID。

When I enable this Trigger and try to update tblPerson I get the following error --> Msg 208, Level 16, State 1, Procedure tblPersonIDMap_OnUpdate, Line 15 Invalid object name 'MATRIX.dbo.tblIndentificationMap'. 当我启用此触发器并尝试更新tblPerson时,出现以下错误-> Msg 208, Level 16, State 1, Procedure tblPersonIDMap_OnUpdate, Line 15 Invalid object name 'MATRIX.dbo.tblIndentificationMap'.

This is my UPDATE statement --> 这是我的UPDATE语句->

`  use Connect
  update tblPerson
  set MiddleName = 'Fakey'
  where PersonID = 258243`

And this is my Trigger --> 这是我的触发器->

ALTER TRIGGER [dbo].[tblPersonIDMap_OnUpdate] 


ON  [dbo].[tblPerson] 
   AFTER UPDATE
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;





UPDATE MATRIX.dbo.tblIndentificationMap
        SET     m.PersonID = i.PersonID
                ,m.FirstName = i.FirstName
                ,m.MiddleName = i.MiddleName
                ,m.LastName = i.LastName

    FROM MATRIX.dbo.tblIdentificationMap m, inserted i, deleted d
    WHERE d.PersonID = m.PersonID
END

Replace 更换

UPDATE MATRIX.dbo.tblIndentificationMap

with

m

in the first line. 在第一行。 Also in the SET area you don't need the references to m (although I don't think they do any harm, it makes it a smidgeon harder to maintain). 同样在SET区域中,您不需要引用m(尽管我认为它们没有任何危害,但这使其更难维护)。

Your SET statement is confused as you're inconsistently referring to the alias and the real name. 由于不一致地引用别名和真实姓名,因此SET语句感到困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM