Sql server select语句(在原始示例中)当您在事务中运行它时,将显示查询2可以在提交之前对查询1的数据执行可重复读取。在两个更新查询之前添加select*from locks where lockname='a',您将发现您可以在不应该读取数据的时候读取数据。我文
Sql server select语句(在原始示例中)当您在事务中运行它时,将显示查询2可以在提交之前对查询1的数据执行可重复读取。在两个更新查询之前添加select*from locks where lockname='a',您将发现您可以在不应该读取数据的时候读取数据。我文,sql-server,locking,rowlocking,Sql Server,Locking,Rowlocking,select语句(在原始示例中)当您在事务中运行它时,将显示查询2可以在提交之前对查询1的数据执行可重复读取。在两个更新查询之前添加select*from locks where lockname='a',您将发现您可以在不应该读取数据的时候读取数据。我文章的全部要点是,在提交数据之前,我不想读取数据,这不应阻止我读取未包含在该读取中的未读取行。output inserted.是选择项。除此之外,从lockname='A'所执行操作的锁中进行选择:更新后的块。我以前见过一些人不听劝告,但你把标准
select语句(在原始示例中)当您在事务中运行它时,将显示查询2可以在提交之前对查询1的数据执行可重复读取。在两个更新查询之前添加
select*from locks where lockname='a'
,您将发现您可以在不应该读取数据的时候读取数据。我文章的全部要点是,在提交数据之前,我不想读取数据,这不应阻止我读取未包含在该读取中的未读取行。output inserted.
是选择项。除此之外,从lockname='A'
所执行操作的锁中进行选择:更新后的块。我以前见过一些人不听劝告,但你把标准定得太高了。。。
begin transaction
select lockname from locks where lockname='A'
update Locks Set locked=1 where lockname='A'
begin transaction
select lockname from locks where lockname='A'
CREATE TABLE [dbo].[Locks](
[LockName] [varchar](50) NOT NULL,
[Locked] [bit] NOT NULL,
CONSTRAINT [PK_Locks] PRIMARY KEY CLUSTERED ([LockName]));
GO
insert into Locks (LockName, Locked) values ('A', 0);
insert into Locks (LockName, Locked) values ('B', 0);
GO
begin transaction
update Locks
set Locked=1
output inserted.*
where LockName = 'A';
begin transaction
update Locks
set Locked=1
output inserted.*
where LockName = 'B';
begin transaction
select lockname from locks where lockname='A'
update Locks Set locked=1 where lockname='A'
begin transaction
update Locks
Set locked=1
output inserted.*
where lockname='A'
create table Resources (
id int identity(1,1) not null,
enqueue_time datetime not null default getutcdate(),
is_processing bit not null default 0,
payload xml);
create clustered index cdxResources on Resources
(is_processing, enqueue_time);
go
-- enqueue:
insert into Resources (payload) values ('<do>This</do>');
insert into Resources (payload) values ('<do>That</do>');
insert into Resources (payload) values ('<do>Something</do>');
insert into Resources (payload) values ('<do>Anything</do>');
--dequeue
begin transaction;
with cte as (
select top(1) *
from Resources with(readpast)
where is_processing = 0
order by enqueue_time)
update cte
set is_processing = 1
output inserted.*;