![]() ![]() ![]() |
To select and output data from a database, you create a ColdFusion application page that includes both CFML and HTML. The application page contains sections for selecting the data and for outputting the results of the selection.
This section introduces ColdFusion data source queries using the Structured Query Language (SQL) in a CFQUERY tag.
The first step is to define a query to select data from a database. ColdFusion uses the CFQUERY tag to define queries. The full syntax for the CFQUERY tag is:
<CFQUERY NAME="query_name" DATASOURCE="ds_name" USERNAME="username" PASSWORD="password" MAXROWS="number" TIMEOUT="milliseconds" BLOCKFACTOR="1" (default) DBPOOL="database connection pool name" DEBUG="yes/no"> SQL statements </CFQUERY>
If a SQL statement becomes too long to fit on a single line, you can split it across multiple lines.
Here is a simple example from a database called Company associated with an ODBC data source named CompanyDB.
To create a query called "EmployeeList" that retrieves all of the records in the Employees table, use this syntax:
<CFQUERY NAME="EmployeeList" DATASOURCE="CompanyDB"> SELECT * FROM Employees </CFQUERY>
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.