SQL的存储过程里,其中一条语句出现错误,如何让整个存储过程都不执行
我建了一个存储过程,其中有6条insert语句.我想让它只要其中一条出错就不能执行整个存储过程.要怎么做?ALTERPROCEDURE[dbo].[Chejiaxinxi...
我建了一个存储过程,其中有6条insert语句.
我想让它 只要其中一条出错就不能执行整个存储过程.要怎么做?
ALTER PROCEDURE [dbo].[Chejiaxinxi]
@frameid int ,
@frametype smallint,
@dateT smalldatetime,
@HJ VArchar(5),
@WBZL char(1),
@NBZL char(1),
@HJGS int,
@ZP1 VArchar(5),
@ZP2 VArchar(5)=null,
@ZP3 VArchar(5)=null,
@ZP4 VArchar(5)=null,
@zpcount tinyint,
@ZPGS int ,
@XJ1 VArchar(5),
@XJ2 VArchar(5) = null ,
@xjcount tinyint,
@XJGS int
AS
begin
SET NOCOUNT ON;
INSERT INTO [banhandb].[Production].[ChejiaProductHeader]([FrameID],[FrametypeID],[Date])VALUES(@frameid,@Frametype,@datet)
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[OutsideQuality],[InsideQuality],[Count],[ManHour])VALUES(
@frameid,@hj,1,@wbzl,@nbzl,1,@hjgs )
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@FrameID,@zp1,2,@zpcount,@zpgs)
if @zp2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp2,2,@zpcount,@zpgs)
end
if @zp3 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp3,2,@zpcount,@zpgs)
end
if @zp4 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp4,2,@zpcount,@zpgs)
end
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj1,3,@xjcount,@xjgs)
if @xj2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj2,3,@xjcount,@xjgs)
-- Insert statements for procedure here
end
end
这回答也太简单了 展开
我想让它 只要其中一条出错就不能执行整个存储过程.要怎么做?
ALTER PROCEDURE [dbo].[Chejiaxinxi]
@frameid int ,
@frametype smallint,
@dateT smalldatetime,
@HJ VArchar(5),
@WBZL char(1),
@NBZL char(1),
@HJGS int,
@ZP1 VArchar(5),
@ZP2 VArchar(5)=null,
@ZP3 VArchar(5)=null,
@ZP4 VArchar(5)=null,
@zpcount tinyint,
@ZPGS int ,
@XJ1 VArchar(5),
@XJ2 VArchar(5) = null ,
@xjcount tinyint,
@XJGS int
AS
begin
SET NOCOUNT ON;
INSERT INTO [banhandb].[Production].[ChejiaProductHeader]([FrameID],[FrametypeID],[Date])VALUES(@frameid,@Frametype,@datet)
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[OutsideQuality],[InsideQuality],[Count],[ManHour])VALUES(
@frameid,@hj,1,@wbzl,@nbzl,1,@hjgs )
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@FrameID,@zp1,2,@zpcount,@zpgs)
if @zp2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp2,2,@zpcount,@zpgs)
end
if @zp3 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp3,2,@zpcount,@zpgs)
end
if @zp4 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp4,2,@zpcount,@zpgs)
end
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj1,3,@xjcount,@xjgs)
if @xj2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj2,3,@xjcount,@xjgs)
-- Insert statements for procedure here
end
end
这回答也太简单了 展开
5个回答
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
展开全部
begin transaction
每执行一条碧桥姿语句把错误号悔绝累加 在最后判消正断
if @@error <> 0
rollback transaction
else
commit transaction
每执行一条碧桥姿语句把错误号悔绝累加 在最后判消正断
if @@error <> 0
rollback transaction
else
commit transaction
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ALTER PROCEDURE [dbo].[Chejiaxinxi]
@frameid int ,
@frametype smallint,
@dateT smalldatetime,
@HJ VArchar(5),
@WBZL char(1),
@NBZL char(1),
@HJGS int,
@ZP1 VArchar(5),
@ZP2 VArchar(5)=null,
@ZP3 VArchar(5)=null,
@ZP4 VArchar(5)=null,
@zpcount tinyint,
@ZPGS int ,
@XJ1 VArchar(5),
@XJ2 VArchar(5) = null ,
@xjcount tinyint,
@XJGS int
AS
begin
SET NOCOUNT ON;
BEGIN TRAN
INSERT INTO [banhandb].[Production].[ChejiaProductHeader]([FrameID],[FrametypeID],[Date])VALUES(@frameid,@Frametype,@datet)
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[OutsideQuality],[InsideQuality],[Count],[ManHour])VALUES(
@frameid,@hj,1,@wbzl,@nbzl,1,@hjgs )
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@FrameID,@zp1,2,@zpcount,@zpgs)
if @zp2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp2,2,@zpcount,@zpgs)
end
if @zp3 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp3,2,@zpcount,@zpgs)
end
if @zp4 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp4,2,@zpcount,@zpgs)
end
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj1,3,@xjcount,@xjgs)
if @xj2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj2,3,@xjcount,@xjgs)
-- Insert statements for procedure here
end
IF @@ERROR=0
COMMIT TRAN
ELSE
ROLLBACK TRAN
end
@frameid int ,
@frametype smallint,
@dateT smalldatetime,
@HJ VArchar(5),
@WBZL char(1),
@NBZL char(1),
@HJGS int,
@ZP1 VArchar(5),
@ZP2 VArchar(5)=null,
@ZP3 VArchar(5)=null,
@ZP4 VArchar(5)=null,
@zpcount tinyint,
@ZPGS int ,
@XJ1 VArchar(5),
@XJ2 VArchar(5) = null ,
@xjcount tinyint,
@XJGS int
AS
begin
SET NOCOUNT ON;
BEGIN TRAN
INSERT INTO [banhandb].[Production].[ChejiaProductHeader]([FrameID],[FrametypeID],[Date])VALUES(@frameid,@Frametype,@datet)
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[OutsideQuality],[InsideQuality],[Count],[ManHour])VALUES(
@frameid,@hj,1,@wbzl,@nbzl,1,@hjgs )
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@FrameID,@zp1,2,@zpcount,@zpgs)
if @zp2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp2,2,@zpcount,@zpgs)
end
if @zp3 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp3,2,@zpcount,@zpgs)
end
if @zp4 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@zp4,2,@zpcount,@zpgs)
end
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj1,3,@xjcount,@xjgs)
if @xj2 is not null
begin
INSERT INTO [banhandb].[Production].[ChejiaProductRegister]([FrameID],[PersonNumber],[OperationID],[Count],[ManHour])VALUES(
@frameid,@xj2,3,@xjcount,@xjgs)
-- Insert statements for procedure here
end
IF @@ERROR=0
COMMIT TRAN
ELSE
ROLLBACK TRAN
end
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
事务日志
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询