use Community_Assist
--this begins a manual transaction
Begin Tran
--try tries all the code before 
--if there are no errors
--it will execute all the code 
--commit the transaction and exit
--if there is an error it will drop to the catch
--rollback the transaction and print the error message
Begin Try
Insert into Person(
[PersonLastName],
[PersonFirstName],
[PersonEmail],
[PersonEntryDate])
Values('SquarePants',
'SpongeBuddy',
'sponge@bikinibottom.com',
GetDate())
Insert into PersonAddress(
[PersonAddressStreet],
[PersonAddressCity],
[PersonAddressState],
[PersonAddressZip],
[PersonKey])
Values('100 Pinapple lane',
'Bikinibottom',
'se',
'00001',
ident_current('Person'))
Insert into contact(
[ContactNumber],
[ContactTypeKey],
[PersonKey])
Values ('2005551245',
1,
ident_Current('Person'))
Commit tran
End Try
Begin Catch
Rollback tran
print error_message()
End Catch
Select * from Contact
Wednesday, May 18, 2016
Transaction try catch
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment