数据库大并发下的检查唯一值插入.

create     proc [dbo].[Name_Add]
 @Name varchar(50)
as
begin

begin tran
insert Names (Name)
select (@Name) where not exists (select NameId from Names with(HOLDLOCK) where Name = @Name)
commit tran

select NameId,Name from Names with(nolock) where Name = @Name
end

 要点:检查,加锁,插入值在一句sql中完成.这样再大的并发也不怕了.

原文地址:https://www.cnblogs.com/greatqn/p/642834.html