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

To create books in IBM DB2 10:

  1. Open Data Studio.

    This procedure varies by platform. In Windows, for example, choose Start > All Programs > IBM Data Studio > Data Studio Client.

  2. On the Administration Explorer tab (on the left), expand the All Databases folder of the object tree until you find your instance of DB2, right-click the instance, and then choose New Database from the shortcut menu.

    Data Studio
  3. If the New Database dialog box opens, type your user name and password, and then click Finish.

    The New Database tab opens.

  4. In the Details pane on the New Database tab, type books in the Database Name box, specify a location, and then click Run.

    (The default settings are fine for the sample database; there’s no need to change the Storage and Locale panes.)

    A progress meter appears while DB2 creates the database.

    Details pane
  5. When DB2 finishes building the database, the new database books appears below the DB2 instance in the All Databases folder on the Administration Explorer tab.

    Books database tab
  6. 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
  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