Batuhan Ozdal Batuhan Ozdal - 8 months ago 42
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 ?


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