Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Dec 15, 1999

Save Database Resources by Being More Selective

When doing a database query with a SQL statement, it is convenient to use the asterisk (*) to retrieve all of the fields in the table whether you need them or not. However, this inefficient query wastes server time and bandwith. The database spends time figuring out the available field names and data types before getting around to fetching the data. For the most efficiency, use the name of each field that you want in the SQL statement. For example, instead of this code:

 
'Set rs = conn.Execute("SELECT * FROM Employees")

use

 
Set rs = conn.Execute("SELECT LastName FROM Employees")

Here's an ASP script that uses this tip to read only one field, the last name:

 
<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
<!--#include File="adovbs.inc"-->
Set conn = CreateObject("ADODB.Connection")
strConn="Provider=SQLOLEDB;Data Source=p450;Initial Catalog=Northwind;User ID=sa;Password=;"
conn.Open strConn
Set rs = conn.Execute("SELECT LastName FROM Employees")
While Not rs.EOF
    Response.Write rs("LastName") & "<BR>"
    rs.MoveNext
Wend
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
%>
</BODY>
</HTML>
Ken Cox
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap