In SQL Server, concurrent updates can be allowed by using the WITH (ROWLOCK) query hint. This query prompts to obtain a row-level lock for each row returned, allowing other connections to simultaneously update different rows that do not conflict with the current query.
SQL Server Concurrent Updates SQL
Question: How to write a SQL Server query to allow Concurrent updates?
Answer:
Concurrent updates can be allowed in SQL Server using the WITH (ROWLOCK)
query hint.
Details:
ROWLOCK
The query hint tells SQL Server to obtain a row-level lock for each row returned. This allows other connections to simultaneously update different rows that do not conflict with the current query.
The following example illustrates how to use WITH (ROWLOCK)
:
<code class="sql">-- 查询表 Customer 并允许并发更新 SELECT * FROM Customer WITH (ROWLOCK) WHERE LastName = 'Smith';</code>
In the above query, SQL Server will # for table Customer
##LastName Obtain a row-level lock for each row of 'Smith'. This allows other connections to simultaneously update rows in the
Customer table where the
LastName is not 'Smith'.
Note:
query hint may reduce performance because it requires acquiring a lock for each row .
The above is the detailed content of How to write concurrent update sql in sqlserver. For more information, please follow other related articles on the PHP Chinese website!