日期:2014-05-18  浏览次数:20429 次

存儲過程問題?
一個存儲過程中,用flag來區分不同的select 查詢.這個會不會趙成多人使用時,查出的結果并發啊。
ALTER PROC [dbo].[usp_EB_Question_List]
@flag int,
@QuestionCategoryParent nvarchar(100),
@QuestionCategoryId int,
  @parm_val nvarchar(100)
AS
/*
分類查詢
*/
if @flag=11-- 無大類

SELECT QuestionCategoryId as c0,QuestionCategoryParent as c1,QuestionCategoryCN as c2,QuestionCategoryTW as c3,
QuestionCategoryEN as c4,QuestionCategoryVN as c5
from EB_Question_Category with (readpast)
where 1=1 and (QuestionCategoryCN like '%'+@parm_val+'%'
or QuestionCategoryTW like '%'+@parm_val+'%'
or QuestionCategoryEN like '%'+@parm_val+'%'
or QuestionCategoryVN like '%'+@parm_val+'%')
order by c1
if @flag=21-- all
BEGIN
SELECT QuestionTitleId as c0,a.QuestionCategoryId as c1,QuestionCategoryParent as c2,QuestionCategoryCN as c3,QuestionCategoryTW as c4,
QuestionCategoryEN as c5,QuestionCategoryVN as c6,
QuestionTitleCN as c7,QuestionTitleTW as c8,QuestionTitleEN as c9,QuestionTitleVN as c10,DocName as c11
from EB_Question_QuestionTitle a with (readpast) inner join
EB_Question_Category b with (readpast) on a.QuestionCategoryId=b.QuestionCategoryId
where 1=1 
and (QuestionTitleCN like '%'+@parm_val+'%'
or QuestionTitleTW like '%'+@parm_val+'%'
or QuestionTitleEN like '%'+@parm_val+'%'
or QuestionTitleVN like '%'+@parm_val+'%')
order by c2
END



------解决方案--------------------
查询多为共享锁
如果仅是查询这种脏读应该是可以的吧
如果你的业务上不允许一条记录给多个用户读取那你加锁吧
------解决方案--------------------
查询不会造成并发的问题。如果查询的数据正在被修改,会造成查询的阻塞,这个是Sql Server正常的机制。如果你查询的同时不允许修改查询的数据,可以加锁 with (holdlock),但是感觉意义不大
------解决方案--------------------
不会造成并发问题
--------------------
happyflystone :
查询多为共享锁 
如果仅是查询这种脏读应该是可以的吧 
如果你的业务上不允许一条记录给多个用户读取那你加锁吧

------解决方案--------------------
不会有问题
------解决方案--------------------
加好索引,应该不会有阻塞