Explore the efficiency of RS (0) and RS (fieldname) execution

Source: Internet
Author: User
Tags execution query
It has been proved that accessing a recordset element by index number is more than a few times faster than the field name. Querying by strings takes more time and system resources than an integer query.
Therefore, you should be aware of the following two issues when traversing a database:
1. Use of statements of SELECT * as least as possible
When you traverse a small number of fields in a table, the SELECT * statement is inefficient, because the execution of such a statement in fact executes two queries, before executing a SELECT statement, you must first query the system table to determine the name and data type.
2. Before using the recordset RS value, you should assign it to a local variable.
This is especially true for manipulating text/memo fields.
I have found that a local variable in "read mode" is slightly faster than a new call to Rs value from a Recordset, especially when recall a recordset more than once.
Let's look at an example of an asp:
<%
' Create a database connection.
Set rs = Conn.execute ("exec sp_getrecords")
If not rs.eof then
Do as not rs.eof

id = rs (0) ' assigns the RS value to the local variable
fname = RS (1)
LName = RS (2)

' ... Working with local variables

Rs.movenext
Loop
End If
' ... Release the variable and end the connection.
%>
Finally, note that if you change the order of the select list in an SQL statement or stored procedure, pay special attention when assigning values.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.