The following sections briefly describe the main SQL command elements.
A SQL statement always begins with a SQL verb. The following keywords identify commonly used SQL verbs:
Keyword | Description |
---|---|
SELECT |
Retrieves the specified records. |
INSERT |
Adds a new row. |
UPDATE |
Changes values in the specified rows. |
DELETE |
Removes the specified rows. |
Use the following keywords to refine SQL statements:
Keyword | Description |
---|---|
FROM |
Names the data tables for the operation. |
WHERE |
Sets one or more conditions for the operation. |
ORDER BY |
Sorts the result set in the specified order. |
GROUP BY |
Groups the result set by the specified select list items. |
The following basic operators specify conditions and perform logical and numeric functions:
Operator | Description |
---|---|
AND |
Both conditions must be met |
OR |
At least one condition must be met |
NOT |
Exclude the condition following |
LIKE |
Matches with a pattern |
IN |
Matches with a list of values |
BETWEEN |
Matches with a range of values |
= |
Equal to |
<> |
Not equal to |
< |
Less than |
> |
Greater than |
<= |
Less than or equal to |
>= |
Greater than or equal to |
+ |
Addition |
- |
Subtraction |
/ |
Division |
* |
Multiplication |
ColdFusion MX is a case-insensitive programming environment. Case insensitivity means the following statements are equivalent:
<cfset foo="bar"> <CFSET FOO="BAR"> <CfSet FOO="bar">
However, many databases, especially UNIX databases, are case-sensitive. Case sensitivity means that you must match exactly the case of all column and table names in SQL queries.
For example, the following queries are not equivalent in a case-sensitive database:
SELECT LastName FROM EMPLOYEES SELECT LASTNAME FROM employees
In a case-sensitive database, employees and EMPLOYEES are two different tables.
For information on how your database handles case, see the product documentation.
When writing SQL in ColdFusion, keep the following guidelines in mind: