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

怎样解决用户并发数据
有什么办法处理这个存储过程并发吗!
要1个1个的来!!
比如30个人同时执行这个某存储过程
等这个存储过程处理完毕,
下1个人再次接着执行




下面是个同时提交考题的1个存储过程!!!!


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <feifan>
-- Create date: <20008-10-15>
-- Description: <学生答题入库-写表:ot_paper,ot_TestResult>
-- =============================================
ALTER PROCEDURE [dbo].[st_TestTotalInfo_add] 
@paperid INT ,
  @studentid VARCHAR(11) ,
  @serial VARCHAR(20) ,
  @ip VARCHAR(20) ,
  @ret INT OUTPUT
AS 
BEGIN
  SET NOCOUNT ON ;
  SET @ret = 1
  --检测TEMP表的中的题目数和试卷的试题数是不是相等,不相等就退出
  DECLARE @qnum INT ,
  @Answernum INT
  SELECT @qnum = COUNT(id)
  FROM ot_question
  WHERE paperid = @paperid AND stauts = 0 --试卷的试题数
  SELECT @answernum = COUNT(1)
  FROM AnswerTemp.dbo.ot_AnswerRecordsTemp
  WHERE studentid = @studentid AND paperid = @paperid AND serial = @serial
  IF @qnum <> @answernum 
  BEGIN 
  SET @ret = 4 --试题数不相等
  RETURN
  END

  -- begin tran--开始事务

--插入答题记录表*******************
  INSERT INTO ot_AnswerRecords_new ( questionid,qoption,qscore,paperid,studentid,addtime,serial )
  SELECT questionid,qoption,qscore,paperid,studentid,addtime,serial
  FROM AnswerTemp.dbo.ot_AnswerRecordsTemp
  WHERE studentid = @studentid AND paperid = @paperid AND serial = @serial 
   
--记录试题分数和答题人数


  UPDATE ot_paperquestion
  SET test_num = a.test_num + 1,total_score = a.total_score + b.qscore
  FROM ot_paperquestion a ,
  dbo.ot_AnswerRecords_new b
  WHERE b.studentid = @studentid AND b.paperid = @paperid AND serial = @serial AND a.paper_id = b.paperid AND a.question_id = b.questionid

  DECLARE @myscore FLOAT
  SELECT @myscore = SUM(qscore)
  FROM AnswerTemp.dbo.ot_AnswerRecordsTemp
  WHERE studentid = @studentid AND paperid = @paperid AND serial = @serial 
  IF @myscore > 100 
  SET @myscore = 100 
  --更新试卷答题次数和部分
  UPDATE dbo.ot_paper
  SET test_num = test_num + 1,total_score = total_score + @myscore
  WHERE id = @paperid
 
--删除临时记录表
  DELETE FROM AnswerTemp.dbo.ot_AnswerRecordsTemp
  WHERE studentid = @studentid AND paperid = @paperid AND serial = @serial
   
--更新分数
  UPDATE dbo.ot_TestResult
  SET end_date = GETDATE(),test_score = @myscore
  WHERE studentid = @studentid AND paperid = @paperid AND serial = @serial 
   
   
  DECLARE @reward INT --为积分赋值
  SET @reward = CASE WHEN @myscore > 0 AND @myscore < 60 THEN 50
  WHEN @myscore >= 60 AND @myscore < 70 THEN 70
  WHEN @myscore >= 70 AND @myscore < 80 THEN 100
  WHEN @myscore >= 80 AND @myscore < 90 THEN 150
  WHEN @myscore >= 90 AND @myscore < 95 THEN 200
  WHEN @myscore >= 95 AND @myscore < 100 THEN 260
  WHEN @myscore = 100 THEN 300
  END

  --更新用户帐户表的经