SQL Primer
This appendix describes how to use Structured Query Language (SQL) to create recordsets for your dynamic pages. SQL (pronounced sequel) is a language that lets you read and write data from a database. The language has only a few keywords and simple syntax rules, but still allows you to perform sophisticated database operations.
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
The following keywords identify commonly used SQL commands: Keyword Description SELECT Retrieves the specified records from a database INSERT Adds a new record in a database table UPDATE Changes values in specified database records DELETE Removes specified database records The following keywords are used to refine SQL statements: Keyword Description FROM Names the data source for an operation WHERE Sets one or more conditions for the operation ORDER BY Sorts the recordset rows in a specified order GROUP BY Groups the recordset by the specified select list items The following operators specify conditions and perform logical and numeric functions: Operator Meaning = Equal to LIKE Like (wildcards OK) <> Not equal to NOT LIKE Not like (wildcards OK) < Less than > Greater than <= Less than or equal to >= Greater than or equal to AND Both conditions must be met, such as Louisiana AND Texas OR At least one condition must be met, such as Smith OR Smyth NOT Exclude 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 Microsoft Access database, enclose it with # 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.
1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 422