|
SQL: Visual QuickStart Guide, Third EditionCreating the Sample Database - IBM DB2 9 |
To create books in IBM DB2 9:
-
Start 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 commanddb2cc.
The default db2_copy_name is DB2COPY1.
-
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; then choose Create Database > Standard from the pop-up menu.
or
In the left pane, right-click the All Databases folder; then choose Create Database > Standard from the pop-up 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.
-
On the Name page, type
booksin the Database Name box; specify a destination; then click Finish.
(The default settings are fine for the sample database; there's no need to step through the entire wizard.)
A progress box appears while DB2 creates the database.
-
Click Close in the message box that appears when DB2 finishes creating the database.
The new databasebooksappears in the Databases folder and the All Databases folder in Control Center.
-
Open a command prompt (shell), type
db2batch -d books -f books_db2.sql
and then press Enter. The-foption 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). You can add the option-auser[/password]to connect to the database as a specific user.
db2batchdisplays the results. Ignore the messages about undefined names (nonexistent tables) — they're caused by the script'sDROPTABLEstatements, which you'll need to rerunbooks_db2.sqllater to restore the tables to their original states.
-
To run SQL scripts and interactive statements against
books, see "IBM DB2" in Chapter 1.
Tips
-
Instead of
db2batchin step 5, you can use thedb2command-line processor in script mode (see "IBM DB2" in Chapter 1).
-
The script
books_db2.sqldiffers slightly from the standard SQL scriptbooks_standard.sql. In the DB2 script, date literals don't have theDATEkeyword. (The standard dateDATE'2000-08-01'is equivalent to the DB2 date'2000-08-01', for example.)