[ Home ]

Cover of SQL Cover of SQL Tricks Cover of SQL Short Course Cover of SQL Visual QuickStart Guide 3rd Edition

Creating the Sample Database in IBM DB2 8

To create books in IBM DB2 8:

  1. Open Control Center.

    This procedure varies by platform. In Windows, for example, choose Start > All Programs > IBM DB2 > General Administration Tools > Control Center. In Unix or Linux, use the command db2cc.

  2. In the left pane, expand the object tree until you find the Databases folder.

    Control Center’s object tree lets you display and work with system and database objects.

  3. Right-click the Databases folder, and then choose Create > Database Using Wizard from the shortcut menu.

    The Create Database wizard opens.

    Control Center
  4. On the Name page, type books in the Database Name box, specify a destination, and then click Finish.

    (The default settings are fine for the sample database; there’s no need to step through the entire wizard.)

    A progress meter appears while DB2 creates the database.

    Name page
  5. Click No in the message box that appears when DB2 finishes creating the database.

    The new database books appears in the Databases folder in Control Center.

  6. Open a command prompt (shell), type:

    db2sql92 -d books -f books_db2.sql

    and then press Enter. The -f option specifies the name of the SQL file. You can include an absolute or relative pathname (see the “Paths” section in “Running SQL Programs” in Chapter 1 of SQL or SQL Tricks, or in Appendix B of SQL Short Course or SQL Crash Course for Beginners). You can add the option -a user[/password] to connect to the database as a specific user.

    db2sql92 displays the results. Ignore the messages about undefined names (nonexistent tables) — they’re caused by the script’s DROP TABLE statements, which you’ll need to rerun books_db2.sql later to restore the tables to their original states.

    db2sql92
  7. To run SQL scripts and interactive statements against books, see “IBM DB2” in Chapter 1 of SQL or SQL Tricks, or in Appendix B of SQL Short Course or SQL Crash Course for Beginners.

Tips