Batuhan Ozdal Batuhan Ozdal - 1 year ago 124
SQL Question

Rollback if null

I was reading articles about rollback transaction and can't find something like I need. Assume I have a user table. User can update his/her records but I want to rollback if entered value is null. I know there are lots of simple ways to do this like checking with c# if it is null and things like that but point in here is understanding rollback. How can I use rollback with if(null) code ?

Answer Source

Rollback is used with a transaction, a rollback restores the state to what it was when begin tran was executed.

BEGIN TRAN 'tran1'
       INSERT INTO Whatever table...
      IF(... check for null)
        ROLLBACK TRAN 'tran1'
        RETURN 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download