Where can I find a good introduction to SQL locking and transaction strategies

I use locks and transactions similar to a VBA excel programmer trying to write a multithreaded C ++ server for the first time ...

I tried to ask my colleagues for advice, but so far we are doing pretty well (or think so) when developing complex databases, writing fast and efficient queries using the index and restrictions, when necessary, and so on, none of us have good knowledge on this topic.

All the online resources that I found are either syntactic links or mannequins explaining that the transaction begins with a "begin tran" and ends with a commit or rollback.

I also went around SO without success.

I am looking for a list of simple real-world problems, as well as the correct way to solve them.

Example:

Let's say I have a table with one Active bit column, and I don't want to have two active rows at the same time. Of course, many processes may try to insert data at the same time.

  • Should I lock the entire table?
  • or perhaps use a data constraint to prevent the insertion of the second “Active” line?
  • or use a transaction with a repeatable read isolation level?
  • or maybe write:

    update tbFoo set Active = 0 Insert in tbFoo (foo, Active) select 'foo', 1 where does not exist (select * from tbFoo, where Active = 1)

Please do not comment / do not answer this specific problem and my silly suggestions. I'm just trying to determine the fact that I have no clue :)

, ? , SQL Server 2008

, , , .

+3
3

, .

, , , . , , , .

SQL Server "Inside SQL Server 2000" (MSPress), , , , ( Oracle).

+1

Q & A Chas Boyd

, , BOL

SQL 2008 MERGE transaction.safe. , : - ( ) - TABLOCKX MERGE

, ( , :)

+1

, , , SQL-, - , SQL-.

" Microsoft® SQL Server® 2008: T-SQL Programming", .

The Transaction Handling, Concurrency and Error Handling section should help you with the specific problem you are having.

However, I found that I recognized small nuggets from all sections of the book, all of which made my life easier when working with the SQL server.

I know that these days it seems almost nostalgic to buy a paper book, but this is one that I would recommend, since it was difficult for me to get a comprehensive guide online.

+1
source

Source: https://habr.com/ru/post/1703928/


All Articles