Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter passing Vs Table Valued Parameters Vs XML to SQL 2008 from .Net Application

As We are working on a asp .net project there three ways one can update data into database when there are multiple rows updation / insertion required

Let's assume we need to update employee education detail (which could be 1,3,5 or 10 records)

Method to Update Data

  1. Pass value as parameter (Traditional approach), If 10 records are there then 10 round trip required

  2. Pass data as xml and write logic inside your stored procedure to get that data from xml and update the table (only single roundtrip required)

  3. Use Table valued parameters (only single roundtrip required)

Note : Data is available as List, so i need to convert it to xml or any other format if i need to pass.

There are no. of places in entire application we need to update data in bulk (or multiple records)

I just need your suggestions that

  1. Which method will be faster (please mention if there are some other overheads)

  2. Manageability or testability concern with any approach

  3. Any other bottleneck or issue with any of the approach (Serialization /Deserialization concern or limit on size of the data passing)

  4. Any other method you suggest for same operations

Thanks

like image 363
Harryboy Avatar asked Dec 23 '09 09:12

Harryboy


1 Answers

The Table-Valued Parameter approach will most likely be the best approach, since you can update a whole batch of rows at once; after all, you get a table which you can join against easily.

The other approaches both are either row-by-row which is inherently slower, or require a fair bit of mucking on the SQL Server side of thing; this is not only not really fun, usually, but also more error-prone and typically less performant than just simply joining two tables.

This is exactly the scenario the TVP have been introduced for - to solve that "row-by-row" or "messing-around-with-XML" problem. I would believe there's a good reason for Microsoft to introduce this, and if they do, you should definitely give it a good try and see if it works.

But again: that's just a "gut feeling" without really knowing all your details. Only you can really find this out, for yourself, by testing all three options. There are a plethora of other effects and parameters that might come into play that anyone answering can't possibly know....

like image 178
marc_s Avatar answered Sep 30 '22 05:09

marc_s