一剑飞虹

道可道非常道,名可名非常名
posts - 93, comments - 80, trackbacks - 0, articles - 22
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

2007年2月7日

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

posted @ 2007-02-07 08:40 greatqn 阅读(471) 评论(1) 编辑