PC Review


Reply
Thread Tools Rate Thread

What is the best practice to execute multiple "nonQuery" SQL operations in a transaction ?

 
 
TheSteph
Guest
Posts: n/a
 
      16th Jun 2006
Hi,

I need some Advice..

What is the best practice to execute multiple "nonQuery" SQL operations in
a transaction ?

1) Execute all in one "sqlCommand.ExecuteNonQuery();" :

sqlCommand.CommandText =
"DELETE CUSTOMER WHERE CUST_ID = 'ID1' \n" +
"DELETE ORDER WHERE CUST_ID = 'ID1' ";
sqlCommand.ExecuteNonQuery();
transaction.Commit();

2) Or Execute each operation independently ? :

sqlCommand.CommandText =
"DELETE CUSTOMER WHERE CUST_ID = 'ID1'";
sqlCommand.ExecuteNonQuery();
sqlCommand.CommandText =
"DELETE ORDER WHERE CUST_ID = 'ID1' "
sqlCommand.ExecuteNonQuery();
transaction.Commit();

Thanks for advices and comments !


Steph.


 
Reply With Quote
 
 
 
 
Balasubramanian Ramanathan
Guest
Posts: n/a
 
      16th Jun 2006
1)Its better do use the first method since you are saving the trip to server

2)The alternating best way is to use stored procedures for excuting series
of sql statements


"TheSteph" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I need some Advice..
>
> What is the best practice to execute multiple "nonQuery" SQL operations
> in
> a transaction ?
>
> 1) Execute all in one "sqlCommand.ExecuteNonQuery();" :
>
> sqlCommand.CommandText =
> "DELETE CUSTOMER WHERE CUST_ID = 'ID1' \n" +
> "DELETE ORDER WHERE CUST_ID = 'ID1' ";
> sqlCommand.ExecuteNonQuery();
> transaction.Commit();
>
> 2) Or Execute each operation independently ? :
>
> sqlCommand.CommandText =
> "DELETE CUSTOMER WHERE CUST_ID = 'ID1'";
> sqlCommand.ExecuteNonQuery();
> sqlCommand.CommandText =
> "DELETE ORDER WHERE CUST_ID = 'ID1' "
> sqlCommand.ExecuteNonQuery();
> transaction.Commit();
>
> Thanks for advices and comments !
>
>
> Steph.
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple "Add Sender to Blocked Senders List" operations. =?Utf-8?B?KyBTaGF5bmU=?= Microsoft Outlook Discussion 3 31st Oct 2007 07:57 PM
Catching "set" operations for exposed reference types (enlist for processing in transaction) Anders Borum Microsoft C# .NET 2 7th Feb 2006 10:52 PM
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." Ollie Riches Microsoft C# .NET 3 11th Mar 2005 05:23 PM
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." Ollie Riches Microsoft ADO .NET 3 11th Mar 2005 05:23 PM
RE: How to automate multiple "search & replace" operations =?Utf-8?B?QmVySGF2?= Microsoft Access 0 14th Jul 2004 05:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:40 AM.