|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, November 30, 2010 11:41 AM
Points: 7,
Visits: 139
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 2:10 AM
Points: 535,
Visits: 2,295
|
|
Thanks for that. An interesting read, and I like seeing performance figures.
In the non-XML solution you recommend, how does one get the bulk updates from the client application to the server, and into the input table in one database call? In your scenario you are 'updating multiple order detail rows in a data grid at once. The user needs to update the price and quantity for 250 order line items.' I can see how to create the XML to do the update and call the stored procedure in the first two examples, but I don't understand how to stock the user defined table type with the data so easily. Would this be an ASP.NET bulk insert or a multiple-value insert? (INSERT INTO tempTable (FirstCol, SecondCol) VALUES (1,'First'), (2,'Second'), (3,'Third'), (4,'Fourth'), (5,'Fifth') ....) If this is the case, wouldn't the 'traditional' approach of using a temporary table be just as fast? Apologies in advance if I've missed something.
Best wishes,
Phil Factor Simple Talk
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, October 08, 2012 2:32 AM
Points: 1,
Visits: 27
|
|
| And what about using sp_xml_preparedocument to parse XML ?
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Tuesday, June 11, 2013 2:12 AM
Points: 30,
Visits: 216
|
|
Using XML as a input parameter - I wouldn’t use a XML as a input parameter to update a table; mainly to avoid the XML reader operation. - This approach will lock the updating table for extensive period which is not acceptable
Watch out if you are attempting to update a large table using a table value parameter, the chances are that you will lock the updating table for a lengthy period of time causing longer transaction response times on your application which won’t be acceptable.
Some details on table –value parameters http://msdn.microsoft.com/en-us/library/bb510489.aspx
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Sunday, November 04, 2012 12:23 PM
Points: 2,087,
Visits: 3,932
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Sunday, November 04, 2012 12:23 PM
Points: 2,087,
Visits: 3,932
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, January 25, 2012 8:14 AM
Points: 567,
Visits: 512
|
|
jude.pieries (7/8/2010) Using XML as a input parameter - I wouldn’t use a XML as a input parameter to update a table; mainly to avoid the XML reader operation. - This approach will lock the updating table for extensive period which is not acceptable
Watch out if you are attempting to update a large table using a table value parameter, the chances are that you will lock the updating table for a lengthy period of time causing longer transaction response times on your application which won’t be acceptable.
Some details on table –value parameters http://msdn.microsoft.com/en-us/library/bb510489.aspx
Do you have an example of an update statement holding a table lock where the sole reason for the lock escalation was the use of the xml parsing? I have seen normal pessimistic locking behaving when shredding xml in the data tier for use in +1 crud scenarios.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 9:21 PM
Points: 6,388,
Visits: 8,290
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, November 30, 2010 11:41 AM
Points: 7,
Visits: 139
|
|
In the calling ASP.NET application you can create a ADO.NET datatable object and populate the datatable with the data rows from the grid. The datatable would be passed into the stored procedure as a single parameter. The parameter would be declared as DB type Structured. The code would look something like this:
DataTable OrderDetailsDT //Add data to the datatable
SqlCommand Cmd = new SqlCommand( "UspInsertOrderDetails",conn); Cmd.CommandType = CommandType.StoredProcedure; SqlParameter Param = Cmd.Parameters.AddWithValue( "@OrderDetails", OrderDetailsDT); Param.SqlDbType = SqlDbType.Structured;
insertCommand.ExecuteNonQuery();
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, June 17, 2013 10:18 AM
Points: 551,
Visits: 1,153
|
|
Hey Scott, thanks for the article. Florian, thanks for the blog links those were great.
I'm curious how the XML method would perform when used with XML Schema Collections. I'm guessing it'd be better, but not as good as TVP.
|
|
|
|