MS SQL Srvr 2005/2008 on Win Srvr 2003+
I am only updating 1 row at a time, the UPDATE is in response to a user change on a web form.
I am updating a few columns in a table using the PK. The table has 95 columns. Typically 1 FK column and 1 or 2 other columns will be updated. The table has 6 FK’s.
Is it of benefit for me to dynamically generate the UPDATE statement only having the columns being changed in the SET portion of the UPDATE, or stick with the current Stored Procedure using a parameterized update with all of the columns?
Currently, and not subject to immediate change, the data from the web form is posted back to the server and is available for the update. I can’t jump to an AJAX scenario where only changed data is posted back to the server from the client browser at this point.
Thanx,
G
SQL Server reads and writes “pages” that consist of 8kb of data. Typically, a page will contain one or more row.
Since disk I/O is the expensive part of an update, the cost of updating half the columns and all the columns is roughly the same. It will still result in 8kb disk I/O.
There’s another aspect, that usually doesn’t come into play because SQL Server writes in 8kb pages. But imagine your row looks like this:
Now if you update
col1to be 5 bytes longer,col2has to be moved forward by five bytes. So even if you don’t updatecol2, it will still have to be written to disk.