Implementation efficiency of ASP extraction data _ Application Skills

Source: Internet
Author: User
You typically extract data records from a database, you need to use a SQL statement, the query gets the related recordset, and then you select the relevant field from the Recordset, and the related record rows are displayed.

Then, in the process of extracting a series of columns, if the following points are noted, the execution efficiency of the extracted data is greatly increased.

1, explicitly extracted field names

The normal SQL statement extraction record is:
Select * FROM [data_table]
That is, the record value of all fields is extracted from the datasheet data_table.

The SELECT * statement is inefficient in its execution because two queries are actually executed when executing such a statement, and the system table must first be queried to determine the name and data type before executing the SELECT statement.

So use the SELECT * statement as minimal as possible, and use an explicit field name, such as:
Select cn_name,cn_pwd from [data_table]
2, using RS (0) faster than RS (filename)
Set Rs=conn. Execute ("Select Cn_name,cn_pwd from [data_table]")
The recordset RS () can have a write segment name (character type), or a field index number (number) that represents the first few fields in the field list. Like what:
RS (0) means RS ("Cn_name")
RS (1) represents RS ("Cn_pwd")

It has been proved that the recordset element is accessed several times faster than the field name by the index number. Querying by string takes more time and system resources than an integer query.

3, assign the value to the variable before using the recordset RS value
<%
Set Rs=conn. Execute ("Select Cn_name,cn_pwd from [data_table] where cn_id=1")
If not rs.eof then
Do as not rs.eof
Cn_name = rs (0) ' assigns the RS value to the variable
Cn_pwd = RS (1)
' ... Working with variables
Rs.movenext
Loop
End If
Rs.close
Set rs = Nothing
%>

However, when you change the order of the fields in the select list in the SQL statement or stored procedure, you should pay attention to the assignment and processing.
4, of course, using GetRows () is another matter.

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.