SQLServerзֹظݣ¼ַ
1.ʹPrimary KeyUnique Keyݿظ롣
2.ʱʹ
insert into Table(****) select **** where not exists(select 1 from Table where ****);
3.ʹSERIALIZABLE뼶𣬲ʹupdlockxlockʾЧĬϸ뼶ʹ(updlock,holdlock)(xlock,holdlock)
set transaction isolation level SERIALIZABLE
Begin Tran
select 1 from Table with(UPDLOCK) where **** --T֧ŵ£ӵҲǷΧRangeS-UȻסҲѡ
if @@ROWCOUNT = 0
insert into Table (****) values(****);
Commit Tran
set transaction isolation level SERIALIZABLE
Begin Tran
select 1 from Table with(UPDLOCK) where **** --T֧ŵ£ӵҲǷΧRangeS-UȻסҲѡ
if @@ROWCOUNT = 0
insert into Table (****) values(****);
Commit Tran