473,769 Members | 3,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Efficiency of SQL UPDATE vs Recordset .edit/.update

Hi

Using A2003 on XP

I am wondering from the MVP's and others, what is the most efficient way (in
terms of time to process) of updating data in a table, using the
docmd.RunSQL or Recordset 'Edit' and 'Update'?

eg: (if you need it)

1.--------------------------

mysql = "Update [mytable] SET [SomeField] = [somevalue];"
docmd.RunSQL mysql
2.-----------------------

set myrecordset = mydb.OpenRecord set([tablename / sql])
myrecordset.edi t
myrecodset.fiel ds("myfield") = [somevalue]
myrecordset.upd ate
TIA
Michelle


Nov 12 '05 #1
3 15257
On Wed, 4 Feb 2004 14:30:44 +1000, "-Michelle-" <mi********@yah oo.com> wrote:
Hi

Using A2003 on XP

I am wondering from the MVP's and others, what is the most efficient way (in
terms of time to process) of updating data in a table, using the
docmd.RunSQL or Recordset 'Edit' and 'Update'?

eg: (if you need it)

1.--------------------------

mysql = "Update [mytable] SET [SomeField] = [somevalue];"
docmd.RunSQL mysql
2.-----------------------

set myrecordset = mydb.OpenRecord set([tablename / sql])
myrecordset.ed it
myrecodset.fie lds("myfield") = [somevalue]
myrecordset.up date
TIA
Michelle


Well, whichever way is faster, SQL Update vs Recordset, DoCnd,RunSQL is a very
inefficient way to execute a SQL command, and there are other good reasons not
to use it from code. It's better to use the .Execute method of a DAO Detabase
or QueryDef object, or of an ADO Connection or Command object.

With regard to whether the SQL update or the recordset is more efficent, it
depends an awful lot on context, but the SQL is generally better. For one
thing, before you can update a record using a recordset, you must find it. If
this is done with a Where clause in a SELECT statement, you are no making
several calls through the database layer instead of just 1. If you do it with
FindFirst, you are searching through the rows in a recordset with no
optimization at all.

Another factor is that any query, whether it is a SELECT or an UPDATE must
first be compiled before it is run. If you execute a SQL statement
repeatedly, compiling it each time, this will be much slower than if you
compile it once, then execute it multiple times. If you do this with a saved
query that takes parameters, the query will be compiled the first time you run
it, and the compiled state will be saved with the query and reused next time.
If you use a temporary querydef in code and reuse the same querydef multiple
times, it will be compiled the first time you execute it, and the compiled
state will be preserved until the querydef variable is released.

Here's an example using a DAO temporary querydef from code.

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim prmFooID As DAO.Parameter
Dim prmFooName As DAO.Parameter

Set dbs = CurrentDB()
Set qdf = dbs.CreateQuery def("")
qdf.SQL = "UPDATE tblFoo SET tblFoo.FooName= prmFooName " & _
"WHERE tblFoo.FooID=pr mFooID"
Set prmFooID = qdf!prmFooID
Set prmFooName = qdf!prmFooName

prmFooID.Value= 1: prmFooName.Valu e="ABC"
qdf.Execute dbFailOnError ' Takes a brief time to compile before running.
prmFooID.Value= 2: prmFooName.Valu e="DEF"
qdf.Execute dbFailOnError ' Still comiled from previous Execute.
prmFooID.Value= 3: prmFooName.Valu e="GHI"
qdf.Execute dbFailOnError ' Still compiled.

' DAO can be unhappy if we don't clean up our objects in reverse order of
' dependency.
Set prmFooID = Nothing: Set prmFooName = Nothing
Set qdf=Nothing
Set dbs = Nothing
Nov 12 '05 #2
-Michelle- wrote:
Hi

Using A2003 on XP

I am wondering from the MVP's and others, what is the most efficient way (in
terms of time to process) of updating data in a table, using the
docmd.RunSQL or Recordset 'Edit' and 'Update'?


I prefer Currentdb.Execu te strSQL. RunSQL is fine too.

I sometimes will use Add/Update when I want to do an insert using the Insert
Into Table (fields....) Values (.....) command because of all the quote and
comma permutations required to write the SQL string that can be parsed by
Access....a PITA to write....and if the data has single or double quotes it gets
to be even more frustrating whileusing a recordset is easy to write and requires
little or no debugging.

Nov 12 '05 #3
Thank you both for replying. Again, this newsgroup has provided an
invaluable service with information coming from real people in an
understandable format, not just from a reference book.

I couldn't live without the newsgroups.

Thanks
Michelle
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4992
by: Fredrik/Sweden | last post by:
Hi folks ! got this problem... i have a table 'Accounts' in my database, which contains a bunch of users. From the main menu i choose "edit user" and all users in the db are presented in a table. The first column 'Pnr' is a unique ID for each user that i made appear as a link. clicking on one userID should present a form where the picked users userdata is already filled in so i can easily edit it and then move on to submit the form to...
7
4100
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
2
3625
by: Joseph Markovich | last post by:
I'm having some trouble with VB in Access 2000. I have a form that the user enters in just one number (in this case, it's a base salary) and then the program is going to do a bunch of math (which is not all shown) and populate a table with these new, calculated salary values. I know I shouldn't be storing calculated values in the table, but I have to have these numbers in there as a lookup too. Anyway I think I might be getting too...
3
3249
by: Ken | last post by:
The following code results in a recordset where every other record of tblOne has =True. The recordset count is correct but one record is skipped; exactly half the records are updated to True. Why is this occuring and how can I fix it? Using A2K/Win XP. Thank you. Code: Dim rst As ADODB.Recordset
2
28323
by: Nono | last post by:
Hello, I have an Access Database that I want to update using an Excel spreadsheet. When it is new reccords, I know how to do it. Nevertheless when I want to complete the information on a certain row of records which already exist, or if I would like to update it (ie: partially change certain records on a row), I do not know how to :
2
75024
by: DaveN | last post by:
Hi all, I'm trying to update a record in a table with data from text boxes on a form. As a background to this, I managed to add a new record to the table in a similar manner with the following: Set db = CurrentDb Set rs = db.OpenRecordset("Project Table") rs.AddNew rs("Project_Number") = Me!
1
8502
by: Mark Reed | last post by:
Hi All, I'm having a problem with the following code. I've read quite a lot of old posts regarding the issue but none seem to affer a solution. The scenario is. I have a bound form which contains a couple of memo fields. I need to keep some sort of log as to when each update of the memo field occurs so I have locked bot the memo fields on the main form. To edit them, the user double clicks the ememo field which then opens an unbound...
5
2160
by: fieldling | last post by:
I've written the following code to update a recordset but when I run it I get a Run-time error 3020: Update or CancelUpdate without AddNew or Edit. When I debug it highlights the rs.update line. I've serached this forum and others for an answer but no luck. Anyone got any ideas? Thanks Option Compare Database Public Function fImportdata() Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb() Set rs =...
4
5292
by: phill86 | last post by:
Hi, i have a form that runs a query in a recordset on the after update method if i copy and paste one record at a time the query picks up the records in the underlying table but if i paste multiple records the query fails to pick up the set of pasted records i think the after update method is running before the table is properly updated when i paste a group of records I have also tried running the code from the after insert method with no...
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.