Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 vb6 sql

views
     
TSnxfx
post Feb 14 2006, 02:44 PM, updated 20y ago

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


I'm wondering which is better in term of speed and performance.

SQL$ = " select * myTable where 1=0 "
Set myrecordset= New Recordset
myrecordset.Open RecSource$, MainDb, adOpenStatic, adLockOptimistic
myrecordset.AddNew
myrecordset.Fields("name") = "James"
myrecordset.Update
myrecordset.Close

OR

SQL$ = "INSERT INTO myTable(name) VALUES('James')"
myrecordset.Open SQL$, MainDb, adOpenStatic, adLockOptimistic


Please give views and opinions. Thankx.
rebel without a cause
post Feb 14 2006, 05:01 PM

Getting Started
**
Validating
297 posts

Joined: Jan 2003
i'll say the second if all you want to do is just insert a record and do nothing else but then it's really hard to say cause it depends on what you want to achieve mainly cause the first method has its uses as well especially if you want to make an open transaction/connection.
SincerePrayer
post Feb 14 2006, 05:15 PM

love to pray
Group Icon
Elite
1,120 posts

Joined: Jun 2005
nxfx,


Is definitetly the second approach. The reason behind is
  • The server does not need to return the whole set of records back to the client and will never use by the client
  • The server does not need to lock the whole returned records for the purpose of adding
  • The round trip between server and client are lesser. Hence, the time needed is lesser.


Happy Coding smile.gif
TSnxfx
post Feb 15 2006, 08:16 AM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


For the 1st "select * myTable where 1=0" , would it return the record even if the "where 1=0" which is false?
Other than that I do agree with you.
SincerePrayer
post Feb 15 2006, 10:23 AM

love to pray
Group Icon
Elite
1,120 posts

Joined: Jun 2005
nxfx,


Yes, the database server will conduct a search and some processing on this empty SELECT. You won't see much performance hit on small application; but you will see big performance impact on multi-user and multiple hit application.

This is good have a good habbit in writing good code. Remember, this tiny habbit does affect your programming skill and how people look at your skill.


Happy Coding smile.gif
TSnxfx
post Feb 16 2006, 08:35 AM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


Oic, thanks for the enlightenment.

 

Change to:
| Lo-Fi Version
0.0133sec    0.82    5 queries    GZIP Disabled
Time is now: 24th December 2025 - 01:46 AM