inserting into two tables and transaction problem
- From: "Habib" <hpourfard@xxxxxxxxx>
- Date: 30 Jun 2006 00:14:54 -0700
CREATE PROCEDURE SimpleInsert (
@custname custname_type,
@carname carname_type)
AS
BEGIN TRANSACTION
INSERT Customers (CustName) VALUES (@custname)
IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN 1 END
DECLARE @custid int
SELECT @custid = scope_identity()
INSERT Cars (ID, CarName) VALUES (@custid, @carname)
IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN 1 END
COMMIT TRANSACTION
IF no error this works but to test transaction, I chanded the table
name of second insert to 'car' in which doesn't exist and this error
occured (calling sp by ASP .NET page):
Invalid object name 'car'. Transaction count after EXECUTE indicates
that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous
count = 0, current count = 1.
Thanks
Habib
.
- Follow-Ups:
- Re: inserting into two tables and transaction problem
- From: Joe Weinstein
- Re: inserting into two tables and transaction problem
- Prev by Date: Re: left() and right() function in MS SQL vs MS ACCESS
- Next by Date: Re: Differences between SQL2000 Dev. Edition & SQL2005 Dev. Edition
- Previous by thread: Sending email (recipients)
- Next by thread: Re: inserting into two tables and transaction problem
- Index(es):
Relevant Pages
|