Skip to content

Instantly share code, notes, and snippets.

@steegi
Created June 15, 2012 01:27
Show Gist options
  • Save steegi/2934101 to your computer and use it in GitHub Desktop.
Save steegi/2934101 to your computer and use it in GitHub Desktop.
Script to drop all tables in a DB2 database
#/bin/sh
# Since there is no simple drop all tables from a database command in DB2,
# this script uses a few unix utilities to accomplish the same result
# Note that it assumes that your session is already connected to the database
# and that the schema from which you want to drop the tables has the same name
# as your current user.
db2 "Select 'DROP TABLE', TABLE_NAME from sysibm.tables WHERE TABLE_SCHEMA = UPPER('$USER')" | grep DROP | db2
# When you need to drop tables from another schema then the current user (SCTID)
db2 "Select 'DROP TABLE', TABLE_SCHEMA, '.', TABLE_NAME from sysibm.tables WHERE TABLE_SCHEMA = 'SCTID'" | grep DROP | db2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment