[ 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 9

To create books in IBM DB2 9:

  1. Open Control Center.

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

    The default db2_copy_name is DB2COPY1.

  2. In the left pane, expand the All Systems branch of the object tree until you find the Databases folder for your instance of DB2, right-click the Databases folder, and then choose Create Database > Standard from the shortcut menu.

    or

    In the left pane, right-click the All Databases folder, and then choose Create Database > Standard from the shortcut menu.

    or

    If the Databases folder or the All Databases folder is already selected, click Create New in the Object Details pane (the lower-right pane). (If this pane isn’t visible, choose View menu > Show Object Details Pane.)

    The Create Database wizard opens.

    Control Center
  3. 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
  4. Click Close in the message box that appears when DB2 finishes creating the database.

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

    Databases folder
  5. Open a command prompt (shell), type:

    db2batch -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.

    db2batch 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.

    db2batch
  6. 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