这样看: 窗口1: begin tran select * from tab with(rowlock,xlock) where groupname=8 waitfor delay '0:00:05' commit tran窗口2: select * from tab 比较: 窗口1: begin tran select * from tab with(rowlock,xlock) where groupname=8 waitfor delay '0:00:05' commit tran窗口2: select * from tab with(readpast) 应该可以明白锁到底是干什么的了楼主对锁的理解有问题
select * from tab 默认是允许脏读的?
to wangdehao(找找找(现在很幸福)) 我按你提供的试了一下,select * from tab 和 select * from tab with(readpast) 得出结果是一样得。readpast得意思是跳过已锁定的行,难道是tab没上锁?可是我用 exec sp_lock 查看时发现tab表已经上了行锁了。这到底时怎么回事? 能给我解释一下吗?谢谢!!!
begin tran select * from tab with(rowlock,xlock) where groupname=8 waitfor delay '0:00:05' commit tran窗口2: select * from tab 如果先执行1的话,必须等到1事务执行完毕 2才会执行 因为1上有排他锁窗口1: begin tran select * from tab with(rowlock,xlock) where groupname=8 waitfor delay '0:00:05' commit tran窗口2: select * from tab with(readpast)这个如果先执行1的话,在1事务没完毕的时候2就会有结果,但2的结果不包括groupname=8这条记录 你得到那个结果是因为你2次对1操作事务完毕后才对2进行操作的可以把时间调的再长点就明白了
--如果先执行1的话,必须等到1事务执行完毕 2才会执行 因为1上有排他锁我试验的结果不是这样的呀,1事务没执行完事务2马上就可以出结果。 --这个如果先执行1的话,在1事务没完毕的时候2就会有结果,但2的结果不包括groupname=8这条记录结果和select * from tab是一样的 时间再长也是一样的大哥有时间帮我试一下可以吗?谢谢!!
--sqlserver2000 SP3下 ----生成测试环境 create table tab ( id int, groupname int ) insert tab select 1,8 union all select 2,7 union all select 3,6 union all select 4,9 go ---窗口1begin tran select * from tab with(rowlock,xlock) where groupname=8 waitfor delay '0:00:05' commit tran---窗口2 select * from tab ---窗口2结果(在1执行完后出来) id groupname 1 8 2 7 3 6 4 9 ---窗口2 select * from tab with(readpast) ---窗口2结果(立刻显示) id groupname 2 7 3 6 4 9
--sqlserver2000 RTM 下(没打补丁) ---窗口1begin tran select * from tab with(rowlock,xlock) where groupname=8 waitfor delay '0:00:05' commit tran ---窗口2 select * from tab with(readpast) ---窗口2结果(立刻显示) id groupname ----------- ----------- 1 8 2 7 3 6 4 9---窗口2 select * from tab ---窗口2结果(立刻显示) id groupname ----------- ----------- 1 8 2 7 3 6 4 9 结论:楼主的sqlserver2000补丁没打到sp3以上,我这没别的测试环境了
我是xp上装的个人版的sql2000,我记得好像已经过sp4的补丁了。 select @@version 出现如下信息: Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:18:38 Copyright (c) 1988-2003 Microsoft Corporation Personal Edition on Windows NT 5.1 (Build 2600: Service Pack 2) 这是怎么回事呢??不会是个人版的问题吧?
select * from tab with(rowlock,xlock) where groupname=8 改成 select * from tab with(paglock,xlock) where groupname=8 试试吧
楼主,去www.mylinux.com.cn看看,那里专业资料多,应该能得到解答
不懂为什么?也许是系统的一种机制吧:防死机机制,免得多几个这种查询服务器就挂了!
窗口1:
begin tran
select * from tab with(rowlock,xlock) where groupname=8
waitfor delay '0:00:05'
commit tran窗口2:
select * from tab
比较:
窗口1:
begin tran
select * from tab with(rowlock,xlock) where groupname=8
waitfor delay '0:00:05'
commit tran窗口2:
select * from tab with(readpast)
应该可以明白锁到底是干什么的了楼主对锁的理解有问题
默认是允许脏读的?
我按你提供的试了一下,select * from tab 和 select * from tab with(readpast)
得出结果是一样得。readpast得意思是跳过已锁定的行,难道是tab没上锁?可是我用
exec sp_lock 查看时发现tab表已经上了行锁了。这到底时怎么回事?
能给我解释一下吗?谢谢!!!
select * from tab with(rowlock,xlock) where groupname=8
waitfor delay '0:00:05'
commit tran窗口2:
select * from tab
如果先执行1的话,必须等到1事务执行完毕 2才会执行 因为1上有排他锁窗口1:
begin tran
select * from tab with(rowlock,xlock) where groupname=8
waitfor delay '0:00:05'
commit tran窗口2:
select * from tab with(readpast)这个如果先执行1的话,在1事务没完毕的时候2就会有结果,但2的结果不包括groupname=8这条记录
你得到那个结果是因为你2次对1操作事务完毕后才对2进行操作的可以把时间调的再长点就明白了
--这个如果先执行1的话,在1事务没完毕的时候2就会有结果,但2的结果不包括groupname=8这条记录结果和select * from tab是一样的
时间再长也是一样的大哥有时间帮我试一下可以吗?谢谢!!
--sqlserver2000 SP3下
----生成测试环境
create table tab (
id int,
groupname int
)
insert tab select 1,8
union all
select 2,7
union all
select 3,6
union all
select 4,9
go
---窗口1begin tran
select * from tab with(rowlock,xlock) where groupname=8
waitfor delay '0:00:05'
commit tran---窗口2
select * from tab
---窗口2结果(在1执行完后出来)
id groupname
1 8
2 7
3 6
4 9
---窗口2
select * from tab with(readpast)
---窗口2结果(立刻显示)
id groupname
2 7
3 6
4 9
---窗口1begin tran
select * from tab with(rowlock,xlock) where groupname=8
waitfor delay '0:00:05'
commit tran
---窗口2
select * from tab with(readpast)
---窗口2结果(立刻显示)
id groupname
----------- -----------
1 8
2 7
3 6
4 9---窗口2
select * from tab
---窗口2结果(立刻显示)
id groupname
----------- -----------
1 8
2 7
3 6
4 9
结论:楼主的sqlserver2000补丁没打到sp3以上,我这没别的测试环境了
select @@version 出现如下信息:
Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:18:38 Copyright (c) 1988-2003 Microsoft Corporation Personal Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
这是怎么回事呢??不会是个人版的问题吧?
改成
select * from tab with(paglock,xlock) where groupname=8
试试吧
我的补丁还没有打上,sql2000的补丁有这么大的差别》?