Accessibility

Table of Contents

SQL primer for Dreamweaver users

Syntax basics

One of the most frequently used SQL statements is the SELECT statement, which extracts specified columns from one or more database tables to build a recordset. Here’s the basic syntax for a SELECT statement:

SELECT ColumnName FROM TableName

You can add line breaks, tabs, and other white space to your statements to clarify the logic: SQL ignores all white space. The following example shows a valid statement:

SELECT PaidDues
FROM Members

Note that a query inserted in a dynamic page does not need a semicolon at the end of it. However, a semicolon is required if you address the database directly, such as with the MySQL monitor.

The following keywords identify commonly used SQL commands:

Keyword Description
SELECTRetrieves the specified records from a database
INSERTAdds a new record in a database table
UPDATEChanges values in specified database records
DELETERemoves specified database records

The following keywords are used to refine SQL statements:

Keyword Description
FROMNames the data source for an operation
WHERESets one or more conditions for the operation
ORDER BYSorts the recordset rows in a specified order
GROUP BYGroups the recordset by the specified select list items

The following operators specify conditions and perform logical and numeric functions:

Operator Meaning
=Equal to
LIKEPattern matches (wildcards OK)
<>Not equal to
NOT LIKEPattern does not match (wildcards OK)
<Less than
>Greater than
<=Less than or equal to
>=Greater than or equal to
ANDBoth conditions must be met, such as Louisiana AND Texas
ORAt least one condition must be met, such as Smith OR Smyth
NOTExclude the condition following, such as Paris NOT France

If the item being compared is text, place it in single quotes as in the following example:

...WHERE Country = 'Germany'

If the item being compared is a date and you’re working with a MySQL database, use the date format YYYY-MM-DD and place the date in single quotes:

...WHERE DateOfBirth < '1970-01-01'

If you're working with a Microsoft Access database, use the MM-DD-YYYY format and place the date in # signs:

...WHERE DateOfBirth < #01/01/1970#

Other databases may have their own date conventions. Consult the database system’s documentation. Some database systems may use non-standard SQL syntax in their products. Check your database system’s documentation.