sql server中这些关键字有什么用(UPDLOCK、ROWLOCK READPAST)

What is the use of these keyword in sql server (UPDLOCK, ROWLOCK READPAST)(sql server中这些关键字有什么用(UPDLOCK、ROWLOCK READPAST))
本文介绍了sql server中这些关键字有什么用(UPDLOCK、ROWLOCK READPAST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想知道这些关键字在 sql server (UPDLOCK, ROWLOCK READPAST) 中的用途以及何时使用?我的意思是在什么样的情况下人们会选择 (UPDLOCK, ROWLOCK READPAST).

i like to know what is the use of these keyword in sql server (UPDLOCK, ROWLOCK READPAST) and when to use it? i mean in what kind of situation people go for (UPDLOCK, ROWLOCK READPAST).

1) select top 1 COMMAND
from EXAMPLE_TABLE
with (UPDLOCK, ROWLOCK)
where PROCESSED=false;

看看上面的sql他们用的是UPDLOCK,ROWLOCK什么是UPDLOCK,ROWLOCK?

just see the above sql they use UPDLOCK, ROWLOCK what is UPDLOCK, ROWLOCK?

UPDLOCKROWLOCK 会发生什么?

2) SELECT TOP(1) COMMAND, PROCESSED
  FROM TABLE WITH (READPAST)
  WHERE PROCESSED = 0

什么是READPAST?当我们使用 READPAST 那么会发生什么?

what is READPAST? when we use READPAST then what happen ?

3) UPDATE  OrderTable WITH ( ROWLOCK )
    SET     ProcessorID = @PROCID
    WHERE   OrderID IN ( SELECT TOP ( 20 )
                                        OrderID
                                FROM    OrderTable WITH ( ROWLOCK )
                                WHERE   ProcessorID = 0)

这里上面的 sql 使用 ROWLOCK 进行更新语句以及嵌套的 select 子查询......为什么??

here the above sql use ROWLOCK for update statement and also in nested select sub query......why??

ROWLOCK 会发生什么?

我的要求是请用大量示例解释每一点,以便我可以理解这些关键字的用法.谢谢

it is my request that please explain each point with lots of example in such way as a result i can understand the usage of those keyword. thanks

推荐答案

它们是用于指定锁定方法的 (DML) 语句:

They are (DML) statements for specifying a locking method:

UPDLOCK 将更新锁放置在被选择的行上,直到事务结束.其他事务不能更新或删除该行,但可以选择它.

UPDLOCK places update locks on rows that are being selected until the end of the transaction. Other transaction cannot update or delete the row but they are allowed to select it.

ROWLOCK 将锁放在与页或表锁相对的行级.

ROWLOCK places locks on row level opposed to a page or table lock.

READPAST 被锁定的记录不返回

这是一个同时使用这两个语句的示例,这意味着在第一个事务结束之前,其他事务无法读取更新或删除数据.

This is an example of using both statements, meaning that other transaction cannot read update or delete data until the first transaction ends.

BEGIN TRAN

  select top 1 COMMAND
  from EXAMPLE_TABLE
  with (UPDLOCK, ROWLOCK)
  where PROCESSED=false;

ROLLBACK

这里交易还没有结束:

BEGIN TRANSACTION

      UPDATE TOP(1) EXAMPLE_TABLE
      SET colum1 = colum1 + 1

如果执行select语句,被锁定的记录不返回,例如:

If you execute a select statement records that are locked are not returned, example:

SELECT COUNT(*)

FROM EXAMPLE_TABLE WITH(READPAST)

这篇关于sql server中这些关键字有什么用(UPDLOCK、ROWLOCK READPAST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)