欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SQLServer中防止并發(fā)插入重復(fù)數(shù)據(jù)的方法詳解

 更新時(shí)間:2017年03月19日 09:27:50   作者:萬(wàn)劍齊發(fā)  
本文主要介紹了SQLServer中防止并發(fā)插入重復(fù)數(shù)據(jù)的方法,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧

SQLServer中防止并發(fā)插入重復(fù)數(shù)據(jù),大致有以下幾種方法:

1.使用Primary Key,Unique Key等在數(shù)據(jù)庫(kù)層面讓重復(fù)數(shù)據(jù)無(wú)法插入。

2.插入時(shí)使用條件

insert into Table(****) select **** where not exists(select 1 from Table where ****);

3.使用SERIALIZABLE隔離級(jí)別,并且使用updlock或者xlock鎖提示(等效于在默認(rèn)隔離級(jí)別下使用(updlock,holdlock)或(xlock,holdlock))

set transaction isolation level SERIALIZABLE
Begin Tran
 select 1 from Table with(UPDLOCK) where **** --這里即算有索引支撐的情況下,加的也是范圍鎖RangeS-U,雖然能鎖住,但并發(fā)性能也不佳。
 if @@ROWCOUNT = 0
 insert into Table (****) values(****);
Commit Tran

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論