Useful DB2 Commands

Getting the description of DB2 error NNN

  • db2 ? sql-NNN

Bring up a command window for executing DB2 commands

  • db2cmd

Display the database schema

  • db2look -d hw -i db2admin -w db2adm1N -e -o d:tempschema.txt

Connect to a database, but remain at the DB2 command line processor

  • db2 connect to hw user db2admin using db2adm1N

Displaying existing triggers

  • db2 select text from syscat.triggers
  • db2 “select text || ‘!’ from syscat.triggers” > d:temptriggers.txt
    • NOTE: second version is useful to allow subsequent import into another database
    • There must be a better way of doing this: all suggestions welcome

Displaying existing stored procedures

  • db2 select text from syscat.procedures where text is not null
  • db2 “select text || ‘!’ from syscat.procedures where text is not null” > d:tempprocs.txt
    • NOTE: second version is useful to allow subsequent import into another database
    • There must be a better way of doing this: all suggestions welcome

Execute a file containing ‘!’ delimited SQL statements

  • db2 -td! -f your_file.sql

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply