LucieLastic
Programmer
hi all
I have an update trigger on one of my tables but this doesn't fire when I alter the table with a TQuery. The data does change in the table though. This TQuery is using cached updates but my trigger will be repeated for each row. I also tried it with Cachedupdates and still didn't fire.
The trigger fires perfectly if I edit the table in SQLExplorer.
Any help welcome.
ta
lou
p.s. here's the trigger :-
CREATE TRIGGER [TR_U_SERAUD] ON [Series]
FOR UPDATE
AS
DECLARE @vcErrorMessage varchar(255)
, @BeginTransCount int
SELECT @BeginTransCount = @@TRANCOUNT
BEGIN TRANSACTION
INSERT Series_audit
(mod_id
,modDT
,modType
,UserID
,Series_id
,Season_id
,On_Sale_Date
,Flight_Type_id
,Flight_Frequency_id
,Day_of_week_id
,Tos1,Tos2,Tos3,Tos4)
SELECT d.mod_id
,d.modDT
,'U'
,d.UserID
,d.Series_id
,d.Season_id
,d.On_Sale_Date
,d.Flight_Type_id
,d.Flight_Frequency_id
,d.Day_of_week_id
,d.Tos1, d.Tos2, d.Tos3, d.Tos4
FROM deleted d
JOIN inserted i ON i.Series_id = d.Series_id
WHERE IsNull( i.Mod_id, '') <> IsNull( d.Mod_id, '')
IF @@Error <> 0
BEGIN
SELECT @vcErrorMessage = "Error: Unable to write Update audit record for Series."
GOTO error
END
error:
IF @vcErrorMessage IS NULL
BEGIN
IF @@TRANCOUNT > @BeginTransCount COMMIT TRANSACTION
END
ELSE
BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
RAISERROR ( @vcErrorMessage, 16, 1)
END
I have an update trigger on one of my tables but this doesn't fire when I alter the table with a TQuery. The data does change in the table though. This TQuery is using cached updates but my trigger will be repeated for each row. I also tried it with Cachedupdates and still didn't fire.
The trigger fires perfectly if I edit the table in SQLExplorer.
Any help welcome.
ta
lou
p.s. here's the trigger :-
CREATE TRIGGER [TR_U_SERAUD] ON [Series]
FOR UPDATE
AS
DECLARE @vcErrorMessage varchar(255)
, @BeginTransCount int
SELECT @BeginTransCount = @@TRANCOUNT
BEGIN TRANSACTION
INSERT Series_audit
(mod_id
,modDT
,modType
,UserID
,Series_id
,Season_id
,On_Sale_Date
,Flight_Type_id
,Flight_Frequency_id
,Day_of_week_id
,Tos1,Tos2,Tos3,Tos4)
SELECT d.mod_id
,d.modDT
,'U'
,d.UserID
,d.Series_id
,d.Season_id
,d.On_Sale_Date
,d.Flight_Type_id
,d.Flight_Frequency_id
,d.Day_of_week_id
,d.Tos1, d.Tos2, d.Tos3, d.Tos4
FROM deleted d
JOIN inserted i ON i.Series_id = d.Series_id
WHERE IsNull( i.Mod_id, '') <> IsNull( d.Mod_id, '')
IF @@Error <> 0
BEGIN
SELECT @vcErrorMessage = "Error: Unable to write Update audit record for Series."
GOTO error
END
error:
IF @vcErrorMessage IS NULL
BEGIN
IF @@TRANCOUNT > @BeginTransCount COMMIT TRANSACTION
END
ELSE
BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
RAISERROR ( @vcErrorMessage, 16, 1)
END