代碼我可以使用SQL @@ identity和沒有觸發器嗎?
ALTER PROCEDURE [dbo].[spSocial.QuestionsAddNew]
@IdUser int,
@IdQuestionCategory int,
@Title int,
@Body int,
@CreatedDate int,
@ActivityDate int,
@VotesCount int,
@AnswersCount int,
@ViewedCount int
AS
BEGIN
SET NOCOUNT ON;
insert into
tblSocialQuestions
(IdUser, IdQuestionCategory, Title, Body, CreatedDate, ActivityDate, VotesCount, AnswersCount, ViewedCount)
values
(@IdUser, @IdQuestionCategory, @Title, @Body, @CreatedDate, @ActivityDate, @VotesCount, @AnswersCount, @ViewedCount)
select @@IDENTITY
exec [spSocial.Questions2Users] @IdUser, 'AskedCount', 1
END
據我瞭解
的@@ IDENTITY函數返回同一 會話中創建的 最後一個標識。
會話是數據庫 連接。範圍是當前的 查詢或當前的存儲過程。
如果會話是當前數據庫連接,那麼在ASP .NET用戶請求的多線程環境中使用@@ Identity時沒有問題嗎?
如果10位用戶同時添加一個新問題,並且[spSocial.QuestionsAddNew] 存儲過程在具有相同SqlConnection的多線程環境中執行,使用@@ Identity時沒有問題嗎?
實際上,它是'SCOPE_IDENTITY()'沒有領先的@@ – 2009-12-31 12:24:24
@marc_s:是的,在答案中編輯 – Andomar 2009-12-31 12:34:04