首页数据库SQLServer2005 的查询独占模拟

SQLServer2005 的查询独占模拟

时间2024-02-28 22:42:03发布访客分类数据库浏览998
导读:收集整理的这篇文章主要介绍了SQLServer2005 的查询独占模拟,觉得挺不错的,现在分享给大家,也给大家做个参考。 对于应用来说,我并不提倡人为给记录加锁,这样会惹来很多麻烦,况且...
收集整理的这篇文章主要介绍了SQLServer2005 的查询独占模拟,觉得挺不错的,现在分享给大家,也给大家做个参考。 对于应用来说,我并不提倡人为给记录加锁,这样会惹来很多麻烦,况且锁并不能解决所有问题,如果你有这方面好的经验我们可以进一步交流。
对于应用来说,我并不提倡人为给记录加锁,这样会惹来很多麻烦,况且锁并不能解决所有问题,如果你有这方面好的经验我们可以进一步交流。
复制代码 代码如下:
set nocount on
use tempdb
go
if (object_id ('tb' ) is not null )
drop table tb
go
create table tb (id int identITy (1 , 1 ), name vArchar (10 ), tag int default 0 )
insert into tb (name ) select 'a'
insert into tb (name ) select 'b'
insert into tb (name ) select 'c'
insert into tb (name ) select 'd'
insert into tb (name ) select 'e'
go
update top (2 ) tb with (rowlock , readpast ) set tag = 1 output inserted . id , inserted . name where tag = 0
go
update top (2 ) tb with (rowlock , readpast ) set tag = 1 output inserted . id , inserted . name where tag = 0
go
update top (2 ) tb with (rowlock , readpast ) set tag = 1 output inserted . id , inserted . name where tag = 0
go
set nocount off
/*
id name
----------- ----------
1 a
2 b
id name
----------- ----------
3 c
4 d
id name
----------- ----------
5 e
*/

如果你有更好的建议,我们不妨探讨一下。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: SQLServer2005 的查询独占模拟
本文地址: https://pptw.com/jishu/632039.html
sqlserver2005 安装图解教程以及SQL 2005 SP3补丁安装图文教程 超详细的sql2005图解安装全过程第1/2页

游客 回复需填写必要信息