Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
desikankannan
Posting Yak Master
152 Posts |
Posted - 2010-06-03 : 01:59:47
|
| hi,i have two tables one is master table another one is detail tablemy questions is that once i commit the master transactions can i rollback that transactionUSE [smartsystem]GO/****** Object: StoredProcedure [dbo].[procstdinstextmaster] Script Date: 06/03/2010 11:21:59 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[procstdinstextmaster](-- insert for createing instrumnet reference value for the external mictro meter@fldrangecode bigint,@fldinsttype bigint)as set nocount ondeclare @autonum bigintbegin transactioninsert into Mst_stdextrefmaster(fldrangecode,fldinsttype) values(@fldrangecode,@fldinsttype)--select @autonum = max(fldexrefno) from mst_stdextrefmaster --select @autonumif @@error <> 0 goto ERR_HANDLERcommit transaction---- i commited Select '0' as Resultreturn 0--Exception HandingERR_HANDLER:print 'unexpected error occurred!'Rollback transactionSelect '1' as Resultreturn 1Desikankannan |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-06-03 : 07:26:19
|
| The simple answer to your question is no, but looking at your code, that is not what you meant to ask. If there is an error during the insert, it will not hit the commit anyway, it will go straight to the error and rollback.If you are using SQL 2005, you may want to change your code to a TRY CATCH block instead as it makes it easier to read and write. |
 |
|
|
desikankannan
Posting Yak Master
152 Posts |
Posted - 2010-06-04 : 01:55:31
|
Hi,can send sample code to use try and catch in sqlquote: Originally posted by RickD The simple answer to your question is no, but looking at your code, that is not what you meant to ask. If there is an error during the insert, it will not hit the commit anyway, it will go straight to the error and rollback.If you are using SQL 2005, you may want to change your code to a TRY CATCH block instead as it makes it easier to read and write.
Desikankannan |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-06-04 : 04:13:35
|
| There are some good examples in Books Online (SQL's help file), it is simple enough:BEGIN TRY... Do processes here.END TRYBEGIN CATCH.. Do error stuff hereEND CATCH |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-06-04 : 05:24:32
|
| You can do a COMMIT / ROLLBACK using a SAVEPOINT - so that you can rollback part of a transaction |
 |
|
|
|
|
|
|
|