Let me explain by an example suppose you are working on a stored procedure which is doing a complex data manipulation. You though this query will run with in 1 minute when you run it from .NET or other code , but some how it took quite long time and with in one minute .NET or the code from which you run the query raised a command timeout.
Or we can say you have applied transaction in stored procedure and calling from .NET code and you have mention the command timeout in .NET .The ADO.NET program raised a timeout but still your query is running in background.
Now in such situation sometimes it happened the transaction which is running in SQL SERVER will be open transaction. Which might be cause of locking problem.
In such situation XACT_ABORT option is helpful.
By default XACT_ABORT option is off you can on it by following statement
SET XACT_ABORT ON;
Now when this statement is on and if you face same situation as mentioned above it will rollback entire batch.
Let me explain with below example
Suppose I wrote following statement “Notice here XACT ABORT is OFF”
![image image](/wp-content/uploads/legacy/e9f839901c54a4250664342d8e590893ecd58f40/image_thumb%25255B1%25255D.png)
Now , when I run the above statements I will get following result in result window
![image image](/wp-content/uploads/legacy/c197d0161c716cb36ffd5534e1283dbe37d97e54/image_thumb%25255B3%25255D.png)
And in the message window we will get following result
![image image](/wp-content/uploads/legacy/8c7ee44ebf863c2eefcced01c510bc4513cef41f/image_thumb%25255B5%25255D.png)
What it means instead of the error at least 3 records are inserted but sometimes you require either all or no record commit in the table then let me enable the option XACT_ABORT ON in the query
![image image](/wp-content/uploads/legacy/3570a90c2acc649145c2887e61cd877f9d34434a/image_thumb%25255B7%25255D.png)
Now let me re run the statements again. When I run the above statements I got following result in message tab there is no result tab.what is means ??
![image image](/wp-content/uploads/legacy/80d6ab7c11da84ce1407bb81cdfed004c260406e/image_thumb%25255B8%25255D.png)
It means what ever inserted is roll backed when an error occurred in a statement. Although The above example is not the best example of XACT_Abort but it will help to understand how to use it.
I appreciate your inputs on this valuable topic.
Thanks
RJ!!!