У меня есть таблица, которая реплицируется с сервера A на сервер B с использованием репликации транзакций.У меня также есть триггер INSERT & UPDATE в таблице на сервере B. Когда агент SQL Server реплицирует данные, возникают блоки, вызванные триггером.
Ниже приведены мои триггеры.
USE [STOREMAIN]
GO
/****** Object: Trigger [dbo].[UPD_tblReceivingHeaderStatus] Script Date: 08/16/2011 13:28:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[UPD_tblReceivingHeaderStatus]
ON [dbo].[tblReceivingHeader]
AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @SeqNum numeric ,@Location numeric
--get the seqnum & location from the inserted record
select @SeqNum = i.SeqNum, @Location = i.Location
from tblReceivingHeaderStatus D
left join inserted i on D.Location = i.Location and D.SeqNum = i.SeqNum
UPDATE tblReceivingHeaderStatus
SET
AdjTax = inserted.AdjTax,
AdjDeliveryFee = inserted.AdjDeliveryFee,
AdjDiscount = inserted.AdjDiscount,
AdjInvoiceTotal = inserted.AdjInvoiceTotal,
AdjItemCount= inserted.AdjItemCount,
AdjInvoiceInfo = inserted.AdjInvoiceInfo,
InvoiceAdjReason = ISNULL(inserted.InvoiceAdjReason,''),
PaidFlag = inserted.PaidFlag,
StartDate = inserted.StartDate,
CheckComments = inserted.CheckComments,
POeMailSent = case inserted.CheckComments
when '.' then 'P'
else ''
end,
PONumber = inserted.PONumber,
[Status] = inserted.[Status],
MiscFlag2 = 'T'
FROM
inserted
WHERE
inserted.seqnum = tblReceivingHeaderStatus.seqnum AND
inserted.location = tblReceivingHeaderStatus.location
;
--this assigns all inventory PO receivers to someone in pricing to approve
update tblReceivingHeaderStatus
set NextApprover = 1
from tblReceivingHeaderStatus
left join apvendp on vmvend = vendornum
where
recdevice = 'P' and
status = '1' and
NextApprover <> 1 and
vminex = 'I'
;
END
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
--------------------------------
USE [STOREMAIN]
GO
/****** Object: Trigger [dbo].[INS_INTO_tblReceivingHeaderStatus] Script Date: 08/16/2011 13:28:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[INS_INTO_tblReceivingHeaderStatus]
ON [dbo].[tblReceivingHeader]
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @SeqNum numeric ,@Location numeric
--get the seqnum & location from the inserted record
select @SeqNum = i.SeqNum, @Location = i.Location
from tblReceivingHeaderStatus D
left join inserted i on D.Location = i.Location and D.SeqNum = i.SeqNum;
INSERT INTO storemain..tblReceivingHeaderStatus
( SeqNum, VendorNum, InvoiceNum, InvoiceTotal, ItemCount, InvoiceDate, Status, Location, AdjTax, AdjDeliveryFee, AdjDiscount, AdjInvoiceTotal,
AdjItemCount, AdjInvoiceInfo, Tax, DeliveryFee, Discount, ApprovedTime, ApprovedDate, ApprovedBy, InvoiceAdjReason, SentTo400, TimeDateSent, PaidFlag,
StartDate, CheckComments, DrayEnteredBy, NextApprover, PONumber, recDevice, SalesTaxFlag, FreightFlag, MiscFlag1, MiscFlag2, MiscFlag3, MiscChar1,
MiscChar2, MiscChar3, MiscNumber1, M