数据库触发器问题... [英] Problem with Database Triggers...

查看:122
本文介绍了数据库触发器问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

我有一个特殊的问题.问题如下:

我有两个数据库lmsbnglr和ilog22july.

我要做的是,当我对lmsbnglr数据库的某些表进行任何更改时,对于这些表,应该在ilog22july中反映相同的更改.

所以我为此写了触发器.

Hie all,

I have a peculiar problem.The problem is as follows:

I have two databases lmsbnglr and ilog22july.

What I have to do is when I make any changes to some tables of lmsbnglr database the same change should get reflected in ilog22july for those tables.

So I wrote triggers for these.

CREATE TRIGGER [dbo].[update_binvoicedet_data]
    ON  [dbo].[BInvoiceDet]
    AFTER INSERT 
AS

BEGIN
 
    SET NOCOUNT ON;

   
        insert into ilog22july.[dbo].binvoicedet

        select * from inserted where where lmsbnglr.dbo.BInvoice.tripstatus=1
                               
END



我收到此错误:

无法绑定多部分标识符"lmsbnglr.dbo.BInvoice.tripstatus".

我要做的是,当我在lmsbnglr中对BInvoiceDet进行更改时,我必须检查Binvoice的tripstatus字段,如果它的值为1,则将数据复制到ilog22july中.

这个怎么做?据我所知,触发器只能在一张桌子上触发.有人可以给我个主意吗?

谢谢你

Swapnil Borkar



I am getting this Error:

The multi-part identifier "lmsbnglr.dbo.BInvoice.tripstatus" could not be bound.

What I have to do is when I make changes to BInvoiceDet in lmsbnglr I have to check the tripstatus field of Binvoice and if it has value 1 then copy the data in ilog22july.

How to do this? As per my knowledge trigger can only be fired on one table. so can anybody give me any idea?

Thanking You

Swapnil Borkar

推荐答案

很正确,触发器只能分配给单个表.如果确定了所有需要同步的目标表,则可以针对这些表编写以下触发器...

Ur very right that a trigger can be assigned to a single table only. If you have identified all the target tables which needs to be synchronized then you can write the following trigger against the tables...

CREATE TRIGGER [dbo].[update_binvoicedet_data]
    ON  [dbo].[BInvoiceDet]
    AFTER INSERT
AS
BEGIN
    SET NOCOUNT ON;

        SELECT * INTO ilog22july.[dbo].binvoicedet
        FROM inserted WHERE lmsbnglr.dbo.BInvoice.tripstatus=1
END


问题出在where子句,因为它包含访问触发器所在表的条件没有创建.
The problem is with the where clause, as it contains the condition which access a table on which trigger is not created.


这篇关于数据库触发器问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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