l xmlns="http://www.w3.org/1999/l">
About This BookThis book will teach you how to use the SQL programming language to maintain and query database information. After some expository material about DBMSes, the relational model, and SQL syntax in Chapters 1 through 3, I revert to the task-based, visual style that you''re familiar with if you''ve read other Visual QuickStart books. Although I don''t assume that you''ve had programming experience, I do expect that you''re competent with your operating system''s filesystem and know how to issue commands at a command prompt or shell (called the DOS prompt in older Windows versions or Terminal in Mac OS X). This book isn''t an exhaustive guide to SQL; I''ve limited its scope to the most-used statements. For information about other SQL statements, refer to your DBMS''s documentation or an SQL reference that covers the standard more completely.
AudienceMy audience is database-application programmers and database end-users (not database designers or administrators), so this book is appropriate for you if you:
|
Proprietary extensions that DBMS vendors add beyond the basic SQL statements.
Advanced programming or administration. I don''t cover installation, privileges, triggers, recursion,[*] stored procedures, replication, backup and recovery, optimization, cursors, collations, character sets, or translations.
[*] To understand recursion, you first must understand recursion.
I use the following typographic conventions:
Italic type introduces new terms or represents replaceable variables in regular text.
Monospace type denotes SQL code and syntax in listings and in regular text. It also shows executables, filenames, directory (folder) names, URLs, and command-prompt text.
Red monospace type highlights SQL code fragments and results that are explained in the accompanying text.
Italic monospace type denotes a variable in SQL code that must be replaced with a value. You''d replace
column with a real column name, for example.
SQL is a free-form language without restrictions on line breaks or the number of words per line, so I use a consistent style in SQL syntax diagrams and code listings to make the code easy to read and maintain:
Each SQL statement begins on a new line.
The indentation level is two spaces.
Each clause of a statement begins on a new, indented line:
SELECT au_fname, au_lname FROM authors ORDER BY au_lname;
SQL is case-insensitive, which means that myname, MyName, and MYNAME are considered to be identical identifiers. I use UPPERCASE for SQL keywords such as SELECT, NULL, and CHARACTER (see "SQL Syntax" in Chapter 3), and lowercase or lower_case for user-defined values, such as table, column, and alias names.
(User-defined identifiers are case sensitive when quoted and in a few other situations for some DBMSes, so it''s safest to respect identifier case in SQL programs.)
Table i.1 shows special symbols that I use in syntax diagrams.
C HARACTERS
| D ESCRIPTION
|
|---|---|
|
| The vertical-bar or pipe symbol separates alternative items. You can choose exactly one of the given items. (Don''t type the vertical bar.) A | B | C is read "A or B or C." Don''t confuse the pipe symbol with the double-pipe symbol, ||, which is SQL''s string-concatenation operator.
|
[]
| Brackets enclose one or more optional items. (Don''t type the brackets.) [A | B | C] means "type A or B or C or type nothing." [D] means "type D or type nothing."
|
{}
| Braces enclose one or more required items. (Don''t type the braces.) {A | B | C} means "type A or B or C".
|
...
| Ellipses mean that the preceding item(s) can be repeated any number of times.
|
()
| Parentheses, unlike the preceding symbols, actually are part of the SQL language; type them as indicated in the syntax diagram.
|
All quote marks in SQL code are straight quotes (such as '' and "), not curly, or smart, quotes (such as '' and "). Curly quotes prevent code from working.
When a column is too narrow to hold a single line of code or out put, I break it into two or more segments. A gray arrow
This icon indicates a vendor-specific departure from the SQL:2003 standard. If you see this icon, it means that a particular vendor''s SQL dialect doesn''t comply with the standard, and you must modify the listed SQL program to run on your DBMS. For example, the standard SQL operator that joins (concatenates) two strings is || (a double pipe), but Microsoft products use + (a plus sign) and MySQL uses the CONCAT() function instead, so you''ll need to change all occurrences of a || b in the example SQL listing to a + b (if you''re using Microsoft Access or Microsoft SQL Server) or to CONCAT( a,b ) (if you''re using MySQL). In most cases, the SQL examples will work as is or with minor syntactic changes. Occasionally, SQL code won''t work at all because the DBMS doesn''t support a particular feature.
|
This book covers the following DBMSes (see the next chapter for details):
Microsoft Access
Microsoft SQL Server
Oracle
IBM DB2
MySQL
PostgreSQL
If you''re using a different DBMS (such as Teradata, Sybase, or Informix), and one of the SQL examples doesn''t work, read the documentation to see how your DBMS''s SQL implementation departs from the SQL standard.