I have a huge list of INSERT INTO ...
strings. Currently I run them with:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
foreach (var commandString in sqlCommandList)
{
SqlCommand command = new SqlCommand(commandString, connection);
command.ExecuteNonQuery();
}
}
I see that each ExecuteNonQuery()
also executes commit.
- Is there a way to insert all rows in a single transaction (commit in the end)?
- The reason I want a single transaction is to make my "inserts" process faster. Will a single transaction also make it quicker?