Some very helpful one liners for db2.
If you are a fan like me to execute db2 commands within the Unix/AIX prompt, rather than going into DB2 inbuilt prompt then all commands run on the fly. Much powerful is Unix prompt as you can modify data in whichever way you want.
If you are a fan like me to execute db2 commands within the Unix/AIX prompt, rather than going into DB2 inbuilt prompt then all commands run on the fly. Much powerful is Unix prompt as you can modify data in whichever way you want.
- db2 list database directory; #Lists all databases within the installation
- db2 list node directory;
- db2 "SELECT SCHEMANAME FROM SYSCAT.SCHEMATA"; #Shows all schema within the Database Instance
- db2 set schema myschema01 # Setting schema before execution
- db2 "LIST TABLES FOR SCHEMA myschema01" | more
- db2 describe indexes for table <table_name> show detail | tr -s " " # shows details about the table including primary key and indexes
- db2 get snapshot for application agentid 228 | more
- # db2 "force applicatioin (228) " #Careful as it forces the session 228 out of DB2
- db2pd -d myDB01 -wlocks
- db2 export to C:\CSVFiles\OutputmyTable.csv of del select * from myTable #For exporting data into CSV files.
- db2 "VALUES CURRENT QUERY OPTIMIZATION" # Checks the current optimisation level. Try changing and resetting it for your queries to run better
- db2look -d<dbname> -z <schema> -t <table_name> -a -e -o output.ddl #db2look utility is very useful in duplicating table and structures . Plenty of flags available including wildcards.
- db2 "select * from syscat.tabconst" # To check table constraints
- db2 "select * from syscat.references" # To check foreign key references of a table
- syscat.keyclouse (contraint details), syscat.checks (contraints at schema level)