Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2015

    Question Unanswered: Drop multiple tables - auto-generating script

    Greetings to all.
    I have some very specific issue. Target is to drop multiple tables in one schema that are older than 3 months and have certain prefix.

    The difficulty is that I need to desing a script, that will generate drop statements automatically, so that I could shedule it to a crontab for daily execution.

    Shortly, I need this two actions:
    db2 "Select 'DROP TABLE ', tabname, ';' from syscat.tables where owner='DBUSER'" >> filename
    db2 -tvf filename>log
    been packed in a script that will generate the list of tables to be dropped and then drop those tables.

    Actually, I have no idea how to do that... Please, give an advice.

    Many thanks!

  2. #2
    Join Date
    Jan 2003
    Provided Answers: 5
    db2 -x "select 'drop table '||trim(tabschema)||'.'||trim(tabname)||';' from syscat.tables where ..." -z drop_script.ddl
    db2 -tvsf drop_script.ddl

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts