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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
Thanks for your registration, follow us on our social networks to keep up-to-date