R
Robert Zurer
Hello All,
In a large production environment, is there be a marked difference in
performance when executing a batch of commands and a single command?
My VERY simple profiling came up with no difference at all between the
following two procedures.
public void Update()
{
StringBuilder sb = new StringBuilder();
sb.Append("UPDATE RECORDINGS SET discID='3001' WHERE id=2001;");
sb.Append("UPDATE RECORDINGS SET title='The Freewheelin'''
WHERE id=2001 ;");
sb.Append("UPDATE RECORDINGS SET artist='Bob Dylan' WHERE id=2001;");
//command is a SqlCommand object and the database is SQLServer
command.ExecuteNonQuery(sb.ToString());
}
public void BatchUpdate()
{
string commandText = UPDATE RECORDINGS SET discID='3001',
title='The Freewheelin''', artist='Bob Dylan' WHERE id=2001");
command.ExecuteNonQuery(sb.ToString());
}
I'm creating a persistence mechanism which in which one field of an
object might map to TableA in DatabaseA and another might map to TableB
in DatabaseB, or, for that matter, to a node in an xml file or some
other storage. I would rather use these granular updates in batch rather
than write code to combine them before execution.
Thanks
Robert Zurer
In a large production environment, is there be a marked difference in
performance when executing a batch of commands and a single command?
My VERY simple profiling came up with no difference at all between the
following two procedures.
public void Update()
{
StringBuilder sb = new StringBuilder();
sb.Append("UPDATE RECORDINGS SET discID='3001' WHERE id=2001;");
sb.Append("UPDATE RECORDINGS SET title='The Freewheelin'''
WHERE id=2001 ;");
sb.Append("UPDATE RECORDINGS SET artist='Bob Dylan' WHERE id=2001;");
//command is a SqlCommand object and the database is SQLServer
command.ExecuteNonQuery(sb.ToString());
}
public void BatchUpdate()
{
string commandText = UPDATE RECORDINGS SET discID='3001',
title='The Freewheelin''', artist='Bob Dylan' WHERE id=2001");
command.ExecuteNonQuery(sb.ToString());
}
I'm creating a persistence mechanism which in which one field of an
object might map to TableA in DatabaseA and another might map to TableB
in DatabaseB, or, for that matter, to a node in an xml file or some
other storage. I would rather use these granular updates in batch rather
than write code to combine them before execution.
Thanks
Robert Zurer