大家好我有一个存储过程,我根据要求去了Transaction,这是我的SP
CREATE PROCEDURE ProcName
@Id INT,
@user_id INT
AS
BEGIN
BEGIN TRANSACTION [transName]
BEGIN TRY
DELETE
FROM table1
WHERE UserId= @user_id
UPDATE table2
SET DATE_MODIFIED = GETDATE()
WHERE ID= @Id
COMMIT TRANSACTION [transName]
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION [transName]
THROW
END CATCH
END
Iam在THROW
附近得到了错误语法等异常可以告诉我哪里出错了
答案 0 :(得分:0)
得到了答案
CREATE PROCEDURE ProcName
@Id INT,
@user_id INT
AS
BEGIN
BEGIN TRANSACTION [transName]
BEGIN TRY
DELETE
FROM table1
WHERE UserId= @user_id
UPDATE table2
SET DATE_MODIFIED = GETDATE()
WHERE ID= @Id
COMMIT TRANSACTION [transName]
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
DECLARE @ErrorNumber INT = ERROR_NUMBER();
DECLARE @ErrorLine INT = ERROR_LINE();
SELECT CAST(ERROR_NUMBER() AS NVARCHAR(1000));
THROW;
END CATCH
END