0

I'm involved in new project right now and I faced with below logic in Sybase ASE trigger:

CREATE TRIGGER TR_TEST2
   ON TBL_TEMP2
FOR INSERT
 AS  
 insert into TBL_TEMP select * from inserted
if @@error != 0
begin
print 'ERROR!!!'
rollback trigger
end

I've checked this trigger with different cases and I can't understand when if @@error != 0 will be treated. If there are some errors in INSERT, the trigger just fails with error and rolled back. And trigger execution will be aborted on the statement which raised error Can someone explain me for what purposes if @@error != 0 is used in triggers and when it can trigger?

  • You should be using `raiserror` and not checking @@error. http://stackoverflow.com/questions/23631224/sybase-is-it-possible-to-set-error – Mike Gardner Feb 08 '17 at 18:22
  • Michael Gardner, thank you for your reply, but I do not need to raise error, I want to understand why logic with @@error is implemented? If INSERT raise an error (for example duplicate values will be inserted), error will be thrown and **if @@error != 0** will never trigger. Have you hot any ideas why **if @@error != 0** is used in triggers? – Walentyna Juszkiewicz Feb 08 '17 at 18:49

1 Answers1

0

I've used for testing Sybase Central v.6.0 And it does't show any PRINT results if error occurs When I've used QTODBC tool for connecting to Sybase ASE server, it threw me exception and printed 'ERROR!!!' message

So, this is the feature of Sybase Central environment Actually, trigger resumes working when any error occurred