PDA

View Full Version : راهنمایی در رابطه با نوشتن یک ک.وری با transaction



soha_smb
یک شنبه 24 فروردین 1393, 08:22 صبح
من یه کوئری برای inserat , update با transaction نوشتم میشه بررسی کنید و ایراد آنرا بگیرید

ALTER PROCEDURE [dbo].[AddForums_Categories]
@Action tinyint,
@Name nvarchar(150),
@R int,
@Status bit,
@AddedBy int,
@ID int
as
IF @Action = 1
BEGIN
begin try
begin transaction
INSERT INTO Forums_Categories
(Name,R,Status,AddedBy )
VALUES (@Name,@R,@Status,@AddedBy)
commit transaction
end try
begin catch
if @@trancount >0 rollback transaction
end catch
END

IF @Action = 2

BEGIN
begin transaction;
begin try
SET NOCOUNT ON;
UPDATE Forums_Categories SET
Name = @Name,
R = @R,
Status = @Status,
UpdatedBy = @AddedBy,
UpdatedOn = (getdate())
WHERE ID =@ID
end try
begin catch
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
print(' عدم ارتباط با دیتا بیس')
if @@trancount >0 rollback transaction
end catch
commit transaction
END



دو مورد رو میخوام بیدونم
1- آیا نوشتم کوئری با Action برای inseart , update درسته؟
2- آیا در مورد transaction در ست عمل کردم یا نه؟ اگر مه چطور با بید اونو بنویسم
با تشکر