Retrieving and Displaying Data
When you query records from a database, the results (known as a record set) are returned in a special ColdFusion data type called a query object. A query object stores the records within it in rows and columns—just like a spreadsheet. Throughout this book, I’ll use the terms record and row interchangeably. Column name and field are also used interchangeably. Before we get into the specifics of querying databases and working with query objects, we need to create a database with some sample data to work with.
Creating the Example Database
The majority of examples in this chapter (and throughout the book)
use a data source called ProgrammingCF that
contains several database tables including one called
EmployeeDirectory. The schema and sample data for
this database are listed in Appendix C. For
simplicity, I’ve chosen to use a Microsoft Access database for
all the examples; you can download the sample Access database from
O’Reilly’s catalog page for this book (http://www.oreilly.com/catalog/coldfusion/).
Of course, you can use any database you choose. To get started, you
need to create a new database and save it as
ProgrammingCF. Next, create a new table and add
the fields shown in Table 4-2.
Table 4-2. Employee Directory Table Within the ProgrammingCF Database
|
Field Name |
Field Type |
Max Length |
|---|---|---|
|
ID (primary key) |
AutoNumber |
N/A |
|
Name |
Text |
255 |
|
Title |
Text |
255 |
|
Department |
Text |
255 |
|
|
Text |
255 |
|
PhoneExt |
Number (long int) |
N/A |
|
Salary |
Number ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access