1

I want to delete all user data from table and insert new. Multiple tasks can do this operation at the same time.

Is seralizable isolation level properly ?

SET TRANSACTION ISOLATION LEVEL Serializable;
BEGIN TRANSACTION;

delete from table where userId = 1
insert into table (userid, somethingData) (1,'somethingData 1')
insert into table (userid, somethingData) (1,'somethingData 2')
insert into table (userid, somethingData) (1,'somethingData 3')

COMMIT TRANSACTION;
2
  • Only you know the answer. (I'll assume that you're using SQL Server since you didn't tag your question the with database software or version.) Of the isolation levels supported, serializable is the most restrictive. In a busy environment it may cause performance issues. You state that multiple tasks could perform the operation simultaneously, but could they do it for the same userId? Is any of the data ever updated or additional data inserted?
    – HABO
    May 10, 2015 at 20:57
  • I use ms sql. And yes, multiple tasks could perform the operation simultaneously with the same userId. The are multiple consumers which process events. Each event carry informationa about user's changed. So is possible, that two cosumers wil be proccess at the same time event with the same userId. So I need protected when two tasks operate on the same user. Only cosumers do delete/insert. Another process do only select on this table for import purposes
    – smagciu
    May 11, 2015 at 21:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.