views:

158

answers:

3

Hi, In our application,Many pages includes "update" and when we update a table,we update unnecessary columns,which dont change,too. i want to know that is there a way to avoid unnecessary column updates?We use stored procedures in .net 2003.In Following link,i found a solution but it is not for stored procedures.

http://blogs.msdn.com/alexj/archive/2009/04/25/tip-15-how-to-avoid-loading-unnecessary-properties.aspx

Thanks

+1  A: 

You can really only accomplish this with a good ORM tool that generates the update query for you. It will typically look at what changed and generate the query for only the columns that changed.

If you're using a stored procedure then all of the column values get sent over to the database anyway when you call the stored procedure so you can't save there. The SP will probably just execute a run-of-the-mill UPDATE statement. The RDMS then takes over. It won't physically change the data on disc if it's not different. It's smart enough for that.

So my answer in short: don't worry about it. It's not really a big deal and requires drastic changes to get what you want and you wont even see performance benefits.

colithium
that is totally not true. most db engines will execute the update regardless. their is still transaction tracking, change logging(if implemented), index updates and foreign key checks. Updating unnecessary columns can definately have an impact, especially if those columns are indexed, even worse if they are part of the clustered index.
Brian Rudolph
I believe Hibernate/NHibernate will do that out of the box. It checks to see if an object is "dirty" (changes made to its properties) and will then create its own SQL statement to update the appropriate columns. Granted, you also get the extra overhead of running an ORM framework, but if the framework is not on the same server as the database, this might help.
Richard Clayton
A: 

colithium,

Our DBA said that we can gain %25 performance for it therefore i wanna find a way to filter changed columns and send it to db by stored procedure.Thanks for ur answer.

This isn't an answer. You can add a comment to an answer by using the 'add comment' link.
g .
Not until he has built up enough reputation, which he has yet to do.
nikc
You can always comment on your own questions.
g .
I stand corrected, I did not know that.
nikc
And apparently, neither did he...
RodeoClown
A: 

When I was working at a financial software company, performance was vital. Some tables had hundreds of columns, and the update statements were costly. We created our own ORM layer (in java) which included an object cache. When we generated the update statement, we compared the current values of every field to the values as they were on load and only updated the changed fields.

Our db was SQLServer. I do not remember the performance improvement, but it was substantial and worth the investment. We also did bulk inserts and updates where possible.

I believe that Hibernate and the other big ORMs all do this sort of thing for you, if you do not want to write one yourself.

Paul Chernoch
u are right,ORM is best way for it