Jac*_*cek 0 sql sql-server stored-procedures transactions
我在 SQL Server 2012 Express 中编写了这个存储过程。
ALTER PROCEDURE [Dictionaries].[InsertCountry]
(@p_countryName nvarchar(128)
, @ret_countryId int OUTPUT)
AS
BEGIN
DECLARE @TransactionName VARCHAR(20) = 'INST_COUNTRY';
BEGIN TRANSACTION @TransactionName;
IF len(@p_countryName) <= 3
BEGIN
SET @ret_countryId = null
ROLLBACK TRANSACTION @TransactionName;
END
INSERT INTO [Dictionaries].[CountryDetails] (name)
VALUES (@p_countryName);
SET @ret_countryId = @@IDENTITY
INSERT INTO [Dictionaries].[Places] (name, Discriminator , CountryDetails_Id, RegionDetails_Id, CityDetails_Id)
VALUES (@p_countryName, 'Country' , @ret_countryId, null, null);
COMMIT TRANSACTION @TransactionName;
END
Run Code Online (Sandbox Code Playgroud)
我以这种方式使用这个方法,但我收到消息
COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION。
代码:
declare @ret int = null
EXEC [Dictionaries].[InsertCountry] 'us', @ret output
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?
| 归档时间: |
|
| 查看次数: |
1048 次 |
| 最近记录: |