Running SQL Programs In this chapter, I'll describe how to run SQL programs on these DBMSes:- Microsoft Access 2003
- Microsoft SQL Server 2000
- Oracle 10g
- IBM DB2 8
- MySQL 5
- PostgreSQL 8
These systems are the most popular commercial and open-source DBMSes. I tested the SQL examples in this book with the indicated releases. The examples will work with later versions but not necessarily with earlier ones. SQL-standard conformance usually improves in successive releases.Microsoft Access's graphical interface lets you run only one SQL statement at a time. The other systems, all DBMS servers, let you run SQL programs in interactive mode or script mode. In interactive mode, you type individual SQL statements at a command prompt and view the results of each statement separately, so input and output are interleaved. In script mode (also called batch mode ), you save your entire SQL program in a text file (called a script or a batch file ), and a command-line utility takes the file, executes the program, and returns the results without your intervention. I use the sample database and the SQL program shown in Listing 1.1 in all the examples in the rest of this chapter. I also describe the minimal syntax of command-line utilities; the complete syntax is given in the DBMS documentation.Listing 1.1. This file, named listing0101.sql, contains a simple SQL SELECT statement, which I'll use to query the sample database in subsequent DBMS examples.

The Command Line Most database professionals prefer to submit commands and SQL scripts through a DBMS's command-line environment rather than mousing around the menus and windows of a graphical front-end. (Database administrators don't add 1,000 users by pointing and clicking.) If you're new to DBMSes, you might find the command line to be cryptic and intimidating, but experience will show you its power, simplicity, and speed. Graphical tools do have a few advantages, though:- Full clipboard support for cut, copy, and paste
- Boundless horizontal and vertical scrolling
- Column widths that you can change by dragging with the mouse
- Better history of the commands and results
Command-line junkies might want to look at HenPlus (http://henplus.sourceforge.net), a free full-featured SQL shell that works across DBMSes. Unix lovers stuck with Windows can run popular Unix shells by using Cygwin (www.cygwin.com) or UWIN (www.research.att.com/sw/tools/uwin). |
Pathnames A pathname specifies the unique location of a directory or file in a filesystem hierarchy. An absolute pathname specifies a location completely, starting at the topmost node of the directory tree, called the root. A relative pathname specifies a location relative to the current (or working) directory. In Windows, an absolute path starts with a backslash (\) or with a drive letter followed by a colon and a backslash. In Unix or Mac OS X Terminal, an absolute path starts with a slash (/).C:\Program Files\Microsoft SQL Server (Windows) and /usr/local/bin/mysql (Unix) are absolute paths, for example. scripts\listing0101.sql (Windows) and doc/readme.txt (Unix) are relative paths. Absolute pathnames for files and folders on a network also can begin with a double backslash and server name (\\someserver, for example).Pathname commonly is shortened to path. Although the difference is obvious from context, I'll use pathname to prevent confusion with the PATH environment variable. |
 |