[ Home ]

SQL 1st cover

SQL (First Edition)
Visual QuickStart Guide
by Chris Fehily

A newer edition is available.

Download this book’s companion files.

Description

SQL: Visual QuickStart Guide teaches SQL — the language of databases — to beginning and intermediate programmers. With SQL, you can create, alter, and drop tables, indexes, and views; insert, update, query, and delete data; and execute transactions to maintain the integrity of your data. This book covers the relational model, the core language for ANSI/ISO (standard) SQL, and product-specific variations for Microsoft Access, Microsoft SQL Server, Oracle, MySQL, and PostgreSQL. Hundreds of examples of varied difficulty encourage you to experiment and explore. Extensive cross references make this book a good quick reference for experienced programmers.

Contents

Introduction
1. DBMS Specifics
2. The Relational Model
3. SQL Basics
4. Retrieving Data From a Table
5. Operators and Functions
6. Summarizing and Grouping Data
7. Retrieving Data From Multiple Tables
8. Subqueries
9. Inserting, Updating, and Deleting Rows
10. Creating, Altering, and Dropping Tables
11. Indexes
12. Views
13. Transactions
Appendix. Creating the Sample Database
Index

Download

This book’s examples use the sample database books, described in “The Sample Database” in Chapter 2. To create books, download the zip file sql_vqs1_files.zip, expand it, and follow the instructions for your DBMS given in the appendix, “Creating the Sample Database.” The file readme.txt describes the distribution.

If you’re running a DBMS locally (that is, on your own computer), then you’re the database administrator (DBA) and have all the privileges you need. If you’re connecting to a DBMS on a network server, then ask your DBA for connection parameters and the privileges to create, query, update, and drop databases and tables.

The instructions for creating the sample database explain how to use simple tools and settings. As you gain experience, you might want to switch to using the statement CREATE DATABASE to create new databases. CREATE DATABASE is a powerful but nonstandard SQL command, so its syntax and capabilities vary by DBMS; see your DBMS’s documentation. (Microsoft Access doesn’t support CREATE DATABASE, but you can create Access databases programmatically by using Visual Basic for Applications or C#.)

Errata and updates

Page 25 — Change the first tip to “Use the FOREIGN KEY constraint to specify a foreign key;...”.

Page 74 — Change the first paragraph of the last tip to “For sorting purposes, Microsoft Access, Microsoft SQL Server, and MySQL treat nulls as the lowest possible values. Oracle and PostgreSQL treat nulls as the highest possible values.”.

Page 235 — In Listing 8.5b, change the SELECT clause to “SELECT DISTINCT a.au_id, a.city”.

Page 235 — In the bottom-most code syntax (the inner-join example), change the SELECT clause to “SELECT DISTINCT table1.*”.

Page 252 — In Listing 8.21, change the WHERE comparison to “WHERE t2.title_id <= t1.title_id”.

Page 302 — In the CREATE TABLE syntax, change “table_contraintN ” to “table_contraintM ”.