create proc P_Insert_New_BookTitle_2K5
(@TitleName nvarchar(128),
@Price money,
@au_fname nvarchar(32),
@au_name nvarchar(64),
@CommissionRating int)
as
declare @err int,
@tablename sysname,
@errormessage nvarchar(2000)
BEGIN TRY
begin transaction
select @errormessage = 'insert into Titles table failed',
@tablename = 'Titles'
insert dbo.Titles (TitleName, Price)
values (@TitleName, @Price)
select @errormessage = 'insert into Authors table failed',
@tablename = 'Authors'
insert dbo.Authors (au_fname, au_lname, TitleID,CommissionRating)
values (@au_fname, @au_fname, @@IDENTITY, @CommissionRating)
commit transaction
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
-- Log the error
insert dbo.Application_Error_Log (UserName, tableName,
errorNumber, errorSeverity, errorState, errorMessage)
values (suser_sname(), @tableName, ERROR_NUMBER(),
ERROR_SEVERITY(), ERROR_STATE(), ERROR_MESSAGE())
RAISERROR (@errormessage, 16,1)
(@TitleName nvarchar(128),
@Price money,
@au_fname nvarchar(32),
@au_name nvarchar(64),
@CommissionRating int)
as
declare @err int,
@tablename sysname,
@errormessage nvarchar(2000)
BEGIN TRY
begin transaction
select @errormessage = 'insert into Titles table failed',
@tablename = 'Titles'
insert dbo.Titles (TitleName, Price)
values (@TitleName, @Price)
select @errormessage = 'insert into Authors table failed',
@tablename = 'Authors'
insert dbo.Authors (au_fname, au_lname, TitleID,CommissionRating)
values (@au_fname, @au_fname, @@IDENTITY, @CommissionRating)
commit transaction
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
-- Log the error
insert dbo.Application_Error_Log (UserName, tableName,
errorNumber, errorSeverity, errorState, errorMessage)
values (suser_sname(), @tableName, ERROR_NUMBER(),
ERROR_SEVERITY(), ERROR_STATE(), ERROR_MESSAGE())
RAISERROR (@errormessage, 16,1)
--返回用户定义的错误信息并设系统标志,记录发生错误。
END CATCH