Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sql server 2008更新是否选择线程安全?_Sql - Fatal编程技术网

sql server 2008更新是否选择线程安全?

sql server 2008更新是否选择线程安全?,sql,Sql,我需要将id为2且statusCode为'Claimed'的表A更新为'booked' 它是线程安全的吗? tks您可以通过在子查询中添加和(updlock,holdlock)来提高并发安全性: UPDATE dbo.A SET StatusCode = 'booked' , UpdateDate = GETDATE() OUTPUT INSERTED.id INTO @TableVar WHERE id = ( SELECT TOP 1 wq.id F

我需要将id为2且statusCode为'Claimed'的表A更新为'booked'

它是线程安全的吗?
tks

您可以通过在子查询中添加
和(updlock,holdlock)
来提高并发安全性:

UPDATE dbo.A  
  SET StatusCode = 'booked' 
   , UpdateDate = GETDATE()
 OUTPUT INSERTED.id INTO @TableVar
 WHERE id = ( 
     SELECT TOP 1 wq.id
     FROM dbo.A AS wq
     WHERE wq.statusCode = 'Claimed' and wq.id = 2

)
一种等效方法是将语句包装为:

这看起来像:

REPEATABLE READ
Specifies that statements cannot read data that has been modified but not yet 
committed by other transactions and that no other transactions can modify data 
that has been read by the current transaction until the current transaction 
completes.
REPEATABLE READ
Specifies that statements cannot read data that has been modified but not yet 
committed by other transactions and that no other transactions can modify data 
that has been read by the current transaction until the current transaction 
completes.
set transaction isolation level repeatable read
start transaction
... your query here ...
commit transaction