Dmitry Tunik Dmitry Tunik - 5 months ago 39
Bash Question

db2 drop few database as once

recently I started to work with db2, and created few databases.

To drop a single DB I should use

db2 drop db demoDB
, is there a way to drop all DBs at once?


Answer Source

first the way to see all the databases on your instance is one of the follow:
1. db2 list db directory
2. db2 list active active databases
depends on your need ( all DBs or just the active DBs)
Im sure there is more DBs lists you can get.(at DB2 user guide)

The way I usually drop all my DBs is by using shell script: 1. create new script by using 'vi' or some other way you want. 2. paste the code: #!/bin/bash -x

for db_name in $(db2 list db directory | grep Database | \
                grep name  | cut -d= -f2); do
        db2 drop db $db_name || true
exit 0

3. save changes
4. and just run the script (after you switched to your instance of course ) sh
Notice that in step 2 you can change the list of DBs as you wish. ( for example to db2 list active databases)

Hope it helped you. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download