using try catch finally in SQL

来源:互联网 发布:游戏特效软件 编辑:程序博客网 时间:2024/06/05 22:52

-- sorry, it looks so like the assemble language struct

 

-- when power not enough, or memory capacity not enough, or other reasons
delete from table1 where id='123456789'


-- @@ERROR is a global error variable, it will err when its variable is not 0
if @@ERROR!=0 goto catch
-- do something, when all are right.

 

-- after do something, you should go to do final thing
goto finally

 

catch:
print 'an exception has occured!'

 

finally:
print 'do something finally'