Reputation: 145
In order to prevent concurrency errors, I've decided to wrap all my sql calls' (which are all in stored procedures) sql statements (all crud operations, such as update / insert/ upserts and even just table reading) with this
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
begin tran--sqlstatements here
OPTION (MAXDOP 1)
COMMIT TRAN
let's just say that I am not concerned about performance. I only want to prevent constraint violations, and deadlocks caused by 2 or more simultaneous threads accessing the same database.
Does this effectively remove all deadlocks and also constraint issues arising from race conditions?
Do I still need to explicitly use with (hold lock, update lock) for CUD functions if I already wrap the calls in a serializable transaction?
Upvotes: 1
Views: 399
Reputation: 51504
It depends what you mean by a "concurrency issue". If you include deadlocks in this, then you may still need to include locking hints (eg: updlock
) in your query
Upvotes: 2