DB2 SQL Query section

/ * 
Part of the SQL 
* / 

- add a primary key 
the ALTER  TABLE TABLE_SCHEMA.TABLE_NAME 
     the Add  constraint A PK_TABLE_NAME
     Primary  Key (COL1, COL2); 

- the collection of statistical information runsats 
the DB2 "RUNSTATS ON  the Table tbschema.tbname with Distribution's ON  All the Columns and the Indexes All " 

/ * 
  the following is a database monitoring section 
* / 
- monitoring of the most time-consuming dynamic SQL user CPU of 
the SELECT STMT_TEXT from sysibmadm.snapdyn_sql the Order  by total_usr_cpu_timedesc  FETCH First 5 rows only 

- the largest number of executions monitor access hotspot objects SQL, <TableName> refers to a hot table name 
the SELECT STMT_TEXT, num_executions 
 from sysibmadm.snapdyn_sql the WHERE stmt like  ' % <TableNameForHotIndex>% ' 
the Order  by num_executions desc  FETCH First 5 rows only 

- controlling access to the highest number of hot spots on the object SQL, <TableNameForHotIndex> index finger hot 
SELECT STMT_TEXT, num_executions 
 from sysibmadm.snapdyn_sql WHERE stmt like  ' % <TableNameForHotIndex>%' 
The Order  by pool_index_p_reads desc  FETCH First 5 rows only 

- monitoring the longest running SQL 
the SELECT  *  from sysibmadm.long_running_sql
 the Order  by elapsed_time_min desc 
FETCH First 1 rows only 

- up to monitor the number of runs SQL 
the SELECT stmt_text, num_executions from sysibmadm.top_dynamic_sql
 the Order  by num_executions desc 
FETCH First 5 Row only 

- monitoring sort highest number of SQL
the SELECT stmt_text, stmt_sorts from sysibmadm.top_dynamic_sql
 the Order  by stmt_sorts desc 
FETCH First 5 Row only 

- log write speed of 
the DB2 " the SELECT (log_write_time_ns / 1000000 ) / num_log_write_io AS average_log_wirte_ms from sysibmadm.snapdb" 

- lock escalation and deadlock 
the DB2 " the SELECT lock_escals, Deadlocks from sysibmadm.snapdb " 

- get all the management view 
the DB2 List the Tables for  Schema SYSIBMADM

- See table structure 
the db2look - D Test - E - nofed - T test.test1 | awk ' / the CREATE TABLE /, /; / Print {} ' 

- view an execution plan 
DB2 Connect to Test 
DB2 "EXPLAIN Plan  for  SELECT  DISTINCT contno from table_schema.table_name " 
the db2exfmt - D Test - . 1  - O / tmp / a.exfmt 
More / tmp / a.exfmt 

- modify table
TABLE_SCHEMA.OLD_TABLENAME RENAME the TO NEW_TABLENAME; 

- Modify table field 
the ALTER  TABLE TABLE_SCHEMA.OLD_TABLENAME the ALTER the COLUMNS the SET the DATA the TYPE VARCHAR ( 10 ); 

- modify the field name [DB2 not modify field names, but the new fields may be deleted] 
the ALTER  TABLE TABLE_SCHEMA.TABLE_NAME the DROP the COLUMNS;
 the ALTER  TABLE TABLE_SCHEMA.TABLE_NAME the ADD the COLUMNS VARCHAR ( 10 );

References:

DB2 design, management and performance optimization Art - Wangfei Peng, Li Yuming, Zhu Zhihui, Wang Fuguo and other school with Mr Woo 

Guess you like

Origin www.cnblogs.com/yangsy/p/db2_yh.html