Question TRANSACTION over multiple ExecuteNonQuery() calls

VentureFree

Well-known member
Joined
Jan 9, 2008
Messages
54
Programming Experience
5-10
Noob here. I've got a normalized database in SQL server comprised of about 7 separate tables. I'm needing to upsert (update if an entry exists, insert if it doesn't) into those tables. My (probably stupid) question is can I start and end a TRANSACTION in separate sql statements (that is to say multiple ExecuteNonQuery() calls) so that I can build each statement and run it before moving on to the next upsert, or do I need to build all of the individual sql statements and combine them into a single ';' delimited statement before running the single ExecuteNonQuery()?

Actually would it be considered more efficient, or maybe just safer, to go ahead and combine all the statements into one anyway?
 
My (probably stupid) question is can I start and end a TRANSACTION in separate sql statements (that is to say multiple ExecuteNonQuery() calls) so that I can build each statement and run it before moving on to the next upsert
In a word, Yes...

It would be exactly like entering two or three SELECT queries into Query Analyser and running them. They will execute in the order in which they are developed.
 
Back
Top