patternMinor
Prevent UPDATE TRIGGER to fire when no changes made in SYBASE
Viewed 0 times
preventtriggerupdatemadesybasefirechangeswhen
Problem
In Sybase I have a main table
This is the update trigger I have:
I tried to use
test and an audit table test_a. The audit table is updated by triggers on insert, update and delete. Now the issue is, when I use update query with old data (no changes), the trigger still gets fired and logs in audit table, which I don't want (to prevent duplication when no changes). test hasId | NAME | DESCtest_a hasupdated_by | date | Id | NAME | DESCThis is the update trigger I have:
create trigger test_utrig on test for update as
insert into audit..test_a select 'update',update_by(),getdate() inserted.* from insertedI tried to use
if (update(Id) or update(NAME) or update(DESC)), but still the update trigger get fired on no changes. Please help me how to stop trigger from firing when no changes are done.Solution
I don't know SyBase but from the documentation, it appears as if you can check whether one or more columns are updated. It should be sufficient to check if one is updated like:
It appears to be a mismatch between the number of columns in the trigger and in the audit table, so I removed the constant 'update'.
create trigger test_utrig on test
for update as
if update (id)
insert into audit..test_a (updated_by, date, Id, ,NAME, DESC)
select update_by(), getdate(), inserted.Id, inserted.NAME, inserted.DESC
from insertedIt appears to be a mismatch between the number of columns in the trigger and in the audit table, so I removed the constant 'update'.
Code Snippets
create trigger test_utrig on test
for update as
if update (id)
insert into audit..test_a (updated_by, date, Id, ,NAME, DESC)
select update_by(), getdate(), inserted.Id, inserted.NAME, inserted.DESC
from insertedContext
StackExchange Database Administrators Q#143922, answer score: 2
Revisions (0)
No revisions yet.