The table contains the following rows:
LastName
Tom
Peter
Smith
Notice that the values inserted in the table were surrounded by single quotation marks. In SQL,
you must surround any text or date values with single quotation marks but numeric values are
not.
Alternatively, you can specify the columns for which you want to insert data. This approach lets
you insert data to some columns while omitting others. The syntax for this approach is as follows:
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)
For example, the syntax to add Kaleigh Smith of Windham, with the address unknown, you use
the named column approach:
INSERT INTO Clients (LastName, FirstName, City)
VALUES ('Smith', 'Kaleigh', 'Windham')
You used the
cfquery
statements to your data source. As described in
Environment," on page
data provider, such as a relational database management system. The data source you established
in that chapter stored information on how to access the Compass Travel database. The data
source name was "CompassTravel".
Exercise: insert trip data using SQL INSERT and cfquery
In this exercise you will add code to pass the data entered on the Trip Maintenance collection
form and insert into the Compass Travel database. To do this, you will be modifying the trip
insert action page to use the SQL INSERT statement and the ColdFusion
To add data using SQL INSERT and cfquery:
Open tripeditaction.cfm in the my_app directory in your editor.
1
Locate the
2
<cfif isOk EQ "Yes">
line, add the following code to insert the data from the Form variables into the Trips
</H1>
table.
FirstName
Jones
Green
Kaleigh
tag to execute SQL from ColdFusion. The
37, a data source stores information about how to connect to an indicated
tag near the end of the file. After the
Address
12 State St
1 Broadway
14 Greenway
cfquery
Chapter 4, "Configuring Your Development
Completing the Trip Maintenance application
City
Boston
New York
Windham
tag passes SQL
tag.
cfquery
<H1>Trip Added
119
Need help?
Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?