devxlogo

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 %><%Set conn = CreateObject("ADODB.Connection")strConn="Provider=SQLOLEDB;Data Source=p450;Initial Catalog=Northwind;User ID=sa;Password=;"conn.Open strConnSet rs = conn.Execute("SELECT LastName FROM Employees")While Not rs.EOF    Response.Write rs("LastName") & "
" rs.MoveNextWendrs.Closeconn.CloseSet rs = NothingSet conn = Nothing%>

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.