SQLServer2005 的查詢獨(dú)占模擬
更新時(shí)間:2009年09月06日 01:13:16 作者:
這個(gè)問(wèn)題一直被很多人關(guān)注,基本上得到的答案是兩種傾向,一種是鎖一種是給記錄打標(biāo)記(也就是update)。
對(duì)于應(yīng)用來(lái)說(shuō),我并不提倡人為給記錄加鎖,這樣會(huì)惹來(lái)很多麻煩,況且鎖并不能解決所有問(wèn)題,如果你有這方面好的經(jīng)驗(yàn)我們可以進(jìn)一步交流。
對(duì)于應(yīng)用來(lái)說(shuō),我并不提倡人為給記錄加鎖,這樣會(huì)惹來(lái)很多麻煩,況且鎖并不能解決所有問(wèn)題,如果你有這方面好的經(jīng)驗(yàn)我們可以進(jìn)一步交流。
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
*/
如果你有更好的建議,我們不妨探討一下。
對(duì)于應(yīng)用來(lái)說(shuō),我并不提倡人為給記錄加鎖,這樣會(huì)惹來(lái)很多麻煩,況且鎖并不能解決所有問(wèn)題,如果你有這方面好的經(jīng)驗(yàn)我們可以進(jìn)一步交流。
復(fù)制代碼 代碼如下:
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
*/
如果你有更好的建議,我們不妨探討一下。
相關(guān)文章
SQLServer2005與SQLServer2008數(shù)據(jù)庫(kù)同步圖文教程
要實(shí)現(xiàn)SQLServer2005與2005的數(shù)據(jù)庫(kù)同步的話,直接用鏡像就可以實(shí)現(xiàn)。但是如果同步 SQLServer2008的話,2005的實(shí)例是連接不上08的。低版本的無(wú)法連接高版本的。所以我們可以通過(guò)復(fù)制的方式,也就是所謂的訂閱發(fā)布的方法來(lái)實(shí)現(xiàn)兩個(gè)不同版本數(shù)據(jù)庫(kù)的數(shù)據(jù)同步。2011-09-09簡(jiǎn)述SQL Server 2005數(shù)據(jù)庫(kù)鏡像相關(guān)知識(shí)
本文我們主要介紹了SQL Server 2005數(shù)據(jù)庫(kù)鏡像的相關(guān)知識(shí),包括數(shù)據(jù)庫(kù)鏡像的優(yōu)點(diǎn)、數(shù)據(jù)庫(kù)鏡像的工作方式等,需要的朋友可以參考下2015-08-08sqlserver中獲取當(dāng)前日期的午夜的時(shí)間值的實(shí)現(xiàn)方法
MS SQLServer,如何獲取當(dāng)前系統(tǒng)日期的午夜的時(shí)間值的方法,需要的朋友可以參考下。2011-09-09SQLServer2005混合模式登錄配置(用戶登錄錯(cuò)誤18452,233,4064)
這篇文章主要介紹了SQLServer2005混合模式登錄配置(用戶登錄錯(cuò)誤18452,233,4064),需要的朋友可以參考下2014-07-07SQLServer2005 中的幾個(gè)統(tǒng)計(jì)技巧
先看下面的一個(gè)表格,我們從左邊的兩列信息來(lái)統(tǒng)計(jì)出右邊的結(jié)果。2009-09-09sql server 關(guān)于設(shè)置null的一些建議
我們?cè)谠O(shè)計(jì)數(shù)據(jù)庫(kù)表的時(shí)候,總有些疑惑,到底是允許為NULL還是不允許為NULL,本文幫大家解除這個(gè)疑惑。2016-05-05SQL Server 2005 模板參數(shù)使用說(shuō)明
如果你用SQL Server 2005 Management Studio建立函數(shù)或存儲(chǔ)過(guò)程,你會(huì)注意到這些新窗口中都是模板。通常,你可以獲得一個(gè)散布著標(biāo)記的框架。2009-01-01