create procedure pd_InsertProduct(@Name varchar(100),@Author varchar(30),@price float,@DctPrice float,@PubDate datetime,@Stock int,@BusinesserNO varchar(100),@Discount int,@Binding varchar(50),@HevayRecomment varchar(250),@LanguageType varchar(100),@Revision int,@PrintingDate datetime,@PublishCompany varchar(150),@Impression int,@EditorRecommentd varchar(max),@InstroContent varchar(max),@Derectory varchar(max),@MediaDiscuss varchar(max),@WorderfulContent varchar(max),@PdTypeID int,@PicNO varchar(100),@AttrNameList varchar(250),@AttrValueList varchar(max))asdeclare @id intbegin traninsert into dbo.Product (Name,Author,Price,DctPrice,PubDate,Stock,ClickNumber,BusinesserNO,Discount,Binding,HevayRecomment,LanguageType,Revision,PrintingDate,PublishCompany,Impression,EditorRecommentd,InstroContent,Derectory,MediaDiscuss,WorderfulContent,PdTypeID,PicNO)values(@Name,@Author,@price,@DctPrice,@PubDate,@Stock,default,@BusinesserNO,@Discount,@Binding,@HevayRecomment,@LanguageType,@Revision,@PrintingDate,@PublishCompany,@Impression,@EditorRecommentd,@InstroContent,@Derectory,@MediaDiscuss,@WorderfulContent,@PdTypeID,@PicNO)select @id=@@IDENTITYif(@@error!=0)rollback tranelsedeclare @AttrName varchar(250)declare @AttrValue varchar(250)declare @AttrNamelog varchar(500)declare @AttrValuelog varchar(500)declare @Number intdeclare @id2 intdeclare @number2 intset @number=charindex(',',@AttrNameList)set @AttrName=left(@AttrNameList,@number-1)set @AttrNamelog=right(@AttrNameList,len(@AttrNameList)-@number)set @number2=charindex(',',@AttrValueList)set @AttrValue=left(@AttrValueList,@number2)set @AttrValuelog=right(@AttrValueList,len(@AttrValueList)-@number2)while(@number>0)begininsert into ProductAtrr(FName,ProductID) values (@AttrName,@id)set @id2=@@identityif(@@error!=0)rollback tranelsebeginset @number=charindex(',',@AttrNamelog)set @AttrName=left(@AttrNamelog,@number-1)set @AttrNamelog=right(@AttrNamelog,len(@AttrNamelog)-@number)insert into dbo.AtrrVal (Description,AttrID) values (@AttrValue,@id2)endif(@@error!=0)beginrollback tranendelsebeginset @number2=charindex(',',@AttrValuelog)set @AttrValue=left(@AttrValuelog,@number2)set @AttrValuelog=right(@AttrValuelog,len(@AttrValuelog)-@number2)endif(@@error!=0)rollback tranelsecommit tranendgo
2 回答
慕尼黑8549860
TA贡献1818条经验 获得超11个赞
实际上tran只有一个,你在上面rollback过了,最后commit当然没有了。每个if都会去判断执行的。rollback不会中断程序。
- 2 回答
- 0 关注
- 2238 浏览
添加回答
举报
0/150
提交
取消