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中完成.这样再大的并发也不怕了.

相关文章:

  • 2022-01-17
  • 2021-10-06
  • 2021-07-14
  • 2021-08-14
  • 2021-09-14
  • 2021-07-04
  • 2022-12-23
猜你喜欢
  • 2021-05-03
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-15
相关资源
相似解决方案