SQL 3rd cover

SQL: Visual QuickStart Guide, Third Edition

Creating the Sample Database - PostgreSQL

To create books in PostgreSQL:

  1. At a command prompt, type:
    createdb -h host -U user -W books
    host is the host name, and user is your PostgreSQL user name. PostgreSQL will prompt you for your password (for a passwordless user, either omit the -W option or press Enter at the password prompt). PostgreSQL creates a new, empty database named books.

    If PostgreSQL is running on a remote network computer, ask your database administrator (DBA) for the connection parameters. If you're running PostgreSQL locally (that is, on your own computer), then set host to localhost, set user to postgres, and use the password that you assigned to postgres when you set up PostgreSQL.

  2. At the command prompt, type:
    psql -h host -U user -W -f books_postgresql.sql books
    The -f option specifies the name of the SQL file. You can include an absolute or relative pathname (see the "Pathnames" sidebar in "Running SQL Programs" in Chapter 1).

    psql displays the results. Ignore the messages about nonexistent tables — they're caused by the script's DROP TABLE statements, which you'll need to rerun books_postgresql.sql later to restore the tables to their original states.

    psql
  3. To run SQL scripts and interactive statements against books, see "PostgreSQL" in Chapter 1.

Tips