posted 15 years ago
Hi!
Let's suppose a database table containing (ID, username, detail1, detail2, status ('d'eleted, 'h'istory, 'a'ctual).
I have a method, that selects the rows that are status='a'ctual and username=desired_new_username. If
the result set is empty, then I insert the new record, else say choose a different username. How can I make
sure, that this works well in multi-threaded environment?
case 1: my single application is hitting the database: is the best approach to make all methods inserting into
this table synchronized with the same lock?
case 2: different, unknown applications are also inserting users into this table. how can I make sure, that
no one can write a new record into that table after my SELECT and before my INSERT?
can this be done by choosing a right transaction isolation level?
thanks for anyone, who answers me!