Pergunta

The following link describes the serializable transaction isolation level.

http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-basics-of-transaction-isolation-levels.aspx

Suppose I have one user updating table [dbo].[Table_A]. And another user is updating table [dbo].[Table_B]. And I want to serialize these two update statements (meaning wait for the first to finish before the second one begins), despite the fact that we are touching different tables. I'm guessing I cannot use a table lock, but perhaps a range lock would accomplish this. Can someone help me understand what the code may look like? Or won't this work with transaction isolation level functionality in SQL Server 2008?

Foi útil?

Solução

You may place application locks:

EXEC  sp_getapplock @resource = 'my_resource_token', @lockMode = 'Exclusive'

UPDATE ...

EXEC  sp_releaseapplock @resource = 'my_resource_token'

This will lock if another session has aquired my_resource_token.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top