我有两个存储过程,一个嵌套在另一个中.当调用嵌套存储过程时,此时它应该在出现外键约束冲突时出错,然后回滚先前的insert以插入到ProductLicense表中.嵌套过程不会对数据库执行任何操作,因为外键违规但调用存储过程没有捕获错误并回滚.如果我自己执行嵌套存储过程,它会返回错误547外键冲突.
如何让两个存储过程一起工作?
外部程序:
ALTER PROCEDURE [dbo].[AddNewLicense2_i]
-- Add the parameters for the stored procedure here
@customerId nvarchar(10),
@licenseModeId int,
@licenseModeProgramId int,
@createdBy int,
@updateBy int,
@systemId nvarchar(50),
@productId int
AS
BEGIN TRY
BEGIN TRANSACTION
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--SET XACT_ABORT ON; --used for automatic rollback when an error occurs
DECLARE @tempDays INT
DECLARE @programCornerAmt INT
DECLARE @tempEndDate DATETIME
DECLARE @tempExpDate DATETIME
DECLARE @err INT
SET …Run Code Online (Sandbox Code Playgroud)