CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Posts
    91

    Performance: rs.update vs if

    Hi,
    maybe one of you knows this (hope this question is not too stupid):
    A recordset is open (function imports data from another database), where 10 fields of a record may have been changed by the user. Ususally at one Session only a very small percentage of the records in fact have been changed, and only one or two fields.
    I could check if there was a change,
    and update only if thats true, or I could update every record.

    My question now is: Which Idea should have a higher performance?

    have a nice day,

    Patzer
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Performance: rs.update vs if

    Fastest should be:
    as user changes a value in a record, mark that record.
    Then build up a Sql statement for updating records whits some changes.
    Sql is faster than editing with ado. Updating fiew records is faster than updating all. Updating some fileds is faster than updating the whole record (but idf you have to update two records with different fields, better execute a single Sql statement for the whole fileds of the two records than two sql for separate fields...)


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    May 2001
    Posts
    91

    Re: Performance: rs.update vs if

    Hi,
    concerning the update of records: as I have no influence on the database where I import the data from, I cannot mark the updated record
    concerning the update of fields: it's obvious that the update of fields lasts some time, but a possible if-statement lasts some time too, and if I include 10 times an if-statement to check if fields in the record have changed, the win in performance of avoiding the update may be (over)comensated by the several if-statements. So to be more precise, how many if statements do I need to compensate an update?

    have a nice day,

    Patzer
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Performance: rs.update vs if

    Now, matter is:
    in memory operations are faster than disk one. So, in general, you may have several "if" and be quicker in any case. But it all depends on free resources: when your Os needs (every MilliSecond on MS Os), it will "swap" 'nd "page", which means "he will write to disk"... So, how many?
    As you already know, the less, the quicker... And there are other factors involved (like position of DB -if remote or local- speed of lan, etc.)

    You should make some trial on your own sistem...



    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured