Click here to Skip to main content
15,921,694 members
Home / Discussions / Database
   

Database

 
AnswerRe: insert_update Stored procedure and return Identity value Pin
wajans6-Nov-08 1:12
wajans6-Nov-08 1:12 
AnswerRe: insert_update Stored procedure and return Identity value Pin
Ben Fair7-Nov-08 2:17
Ben Fair7-Nov-08 2:17 
GeneralRe: insert_update Stored procedure and return Identity value Pin
wajans7-Nov-08 2:55
wajans7-Nov-08 2:55 
QuestionAtomic Sql Statements (Transaction) Pin
Meysam Mahfouzi5-Nov-08 4:41
Meysam Mahfouzi5-Nov-08 4:41 
AnswerRe: Atomic Sql Statements (Transaction) Pin
J4amieC5-Nov-08 4:46
J4amieC5-Nov-08 4:46 
GeneralRe: Atomic Sql Statements (Transaction) Pin
Meysam Mahfouzi5-Nov-08 4:50
Meysam Mahfouzi5-Nov-08 4:50 
AnswerRe: Atomic Sql Statements (Transaction) Pin
Meysam Mahfouzi5-Nov-08 4:48
Meysam Mahfouzi5-Nov-08 4:48 
AnswerRe: Atomic Sql Statements (Transaction) Pin
Wendelius5-Nov-08 8:04
mentorWendelius5-Nov-08 8:04 
There are several considerations in both examples. Some of them are:

1. Transaction usage and scope: In the first example transaction is started and ended inside stored proc. Personally I don't feel this is a good way to handle transactions. Consider what would happen if the real world situation involves call to two stored procs. If both of them autonomously end transaction, there's no quarantee that the result is correct. This is why I always start and end transactions at calling side.

2. Why rollback if first statement fails: Even though the insert itself fails, transaction is started and DML is executed. This has resulted to resource usage. The only way to free those resources is to roll back the transaction (since there's no point to commit a failure).

So basically I would prefer the second version of the stored proc, but I also would ensure that it's executed inside a transaction. This would make it possible to have larger scope transactions and also to retry failed operations inside a transaction which is a very elemental requirement in certain system types.

Mika

The need to optimize rises from a bad design.

My articles[^]

GeneralRe: Atomic Sql Statements (Transaction) Pin
PIEBALDconsult5-Nov-08 13:33
mvePIEBALDconsult5-Nov-08 13:33 
GeneralRe: Atomic Sql Statements (Transaction) Pin
Wendelius6-Nov-08 7:39
mentorWendelius6-Nov-08 7:39 
GeneralRe: Atomic Sql Statements (Transaction) Pin
PIEBALDconsult6-Nov-08 11:27
mvePIEBALDconsult6-Nov-08 11:27 
GeneralRe: Atomic Sql Statements (Transaction) Pin
Wendelius7-Nov-08 6:36
mentorWendelius7-Nov-08 6:36 
Questionsql server 2005 query xml datatype fields Pin
arkiboys5-Nov-08 2:55
arkiboys5-Nov-08 2:55 
AnswerRe: sql server 2005 query xml datatype fields Pin
Wendelius5-Nov-08 10:33
mentorWendelius5-Nov-08 10:33 
GeneralRe: sql server 2005 query xml datatype fields Pin
arkiboys5-Nov-08 10:54
arkiboys5-Nov-08 10:54 
GeneralRe: sql server 2005 query xml datatype fields Pin
Wendelius5-Nov-08 11:13
mentorWendelius5-Nov-08 11:13 
GeneralRe: sql server 2005 query xml datatype fields Pin
arkiboys6-Nov-08 1:50
arkiboys6-Nov-08 1:50 
GeneralRe: sql server 2005 query xml datatype fields Pin
Wendelius6-Nov-08 7:06
mentorWendelius6-Nov-08 7:06 
Questiontransfering data fro one table to another Pin
prasadbuddhika5-Nov-08 1:07
prasadbuddhika5-Nov-08 1:07 
AnswerRe: transfering data fro one table to another Pin
Ashfield5-Nov-08 1:34
Ashfield5-Nov-08 1:34 
GeneralRe: transfering data fro one table to another Pin
prasadbuddhika5-Nov-08 16:08
prasadbuddhika5-Nov-08 16:08 
GeneralRe: transfering data fro one table to another Pin
Ashfield5-Nov-08 21:01
Ashfield5-Nov-08 21:01 
GeneralRe: transfering data fro one table to another Pin
Muditha Dissanayake6-Nov-08 4:39
Muditha Dissanayake6-Nov-08 4:39 
Questionwhere can i find the northwind sql script Pin
prasadbuddhika4-Nov-08 23:58
prasadbuddhika4-Nov-08 23:58 
AnswerRe: where can i find the northwind sql script Pin
cyber-drugs5-Nov-08 0:12
cyber-drugs5-Nov-08 0:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.