You are on page 1of 14

These tennis shots make me win my match in just two sets (1.

5 hours)
DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

SQL 1: Table Counts tableschema wise

select substr(tabschema,1,20)SCHEMA_NAME , count(*) TABLE_CNT, case type when 'A' then 'Alias' when 'w' then 'Created temporary table' when 'H' then 'Hierarchy table' when 'L' then 'Detached table' when 'N' then 'Nickname' when 'S' then 'Materialized query table' when 'T' then 'Table (untyped)' when 'U' then 'Typed table' when 'V' then 'View (untyped)' when 'W' then 'Typed view' end as TABLE_TYPE from syscat.tables where tabschema <> 'SYS%' group by tabschema, type order by 1 with ur
3/23/2013 DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc 2

SCHEMA_NAME CUBE_SCHEMA CUBE_SCHEMA DB2INST1 DB2INST1 DB2INST1 DB2INST1 DB2INST1

TABLE_CNT

TABLE_TYPE 3 Table (untyped) 1 View (untyped) 5 Alias 1 Nickname 1 Materialized query table

40 Table (untyped) 19 View (untyped)

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

SQL 2 : PROCEDURE COUNTS


select substr(procschema,1,15) PROCSCHEMA, count(*) PROCEDURE_CNT from syscat.procedures where procschema not like 'SYS%' group by procschema PROCSCHEMA DB2INST1 PROCEDURE_CNT 3

SQL 3 : TRIGGERS COUNT select substr(trigschema,1,15) TRIGSCHEMA, count(*) TRIGGERS_CNT from syscat.triggers where trigschema not like 'SYS%' group by trigschema
TRIGSCHEMA DB2INST1
3/23/2013

TRIGGERS_CNT 1
DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc 4

SQL 4 : FUNCTIONS COUNT select substr(funcschema,1,15) FUNCSCHEMA, count(*) FUNCTIONS_CNT from syscat.functions where funcschema not like 'SYS%' group by funcschema with ur FUNCSCHEMA DB2INST1 FUNCTIONS_CNT 2

SQL 5 : View Counts


select substr(viewschema,1,15) VIEWSCHEMA, count(*) VIEW_CNT from syscat.views where viewschema not like 'SYS%' group by with ur

VIEWSCHEMA CUBE_SCHEMA DB2INST1


3/23/2013

VIEW_CNT
1 20
5

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

SQL 6 : NICKNAME INFORMATION


select substr(tabschema,1,10)TABSCHEMA, substr(tabname,1,25)TABNAME , substr(wrapname,1,15) WRAPNAME ,substr(N.SERVERNAME,1,10) SERVERNAME , substr(SERVERTYPE,1,10) SERVERTYPE , substr(SERVERVERSIOn,1,10) SERVERVERSION from syscat.nicknames N , SYSCAT.SERVERS S where N.servername = S.SERVERNAME WITH UR
TABSCHEMA DB2INST1 DB2INST1 TABSCHEMA CUSTOMER_ACE CUST_ADDR WRAPNAME DRDA DRDA SERVERNAME ACEDBA10 ACEDBA11 SERVERTYPE DB2/UDB DB2/UDB SERVERVERSION 9.7 9.7

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

select tbspace from syscat.tablespaces where datatype not in ('T', 'U') except (select rtrim(tbspace) from syscat.tables) with ur TBSPACE DMSTBS

SQL 1 : Count of Table spaces without Tables :

SQL 2 : Type of Table spaces :

select substr(tbspace ,1,25)TBSPACE, substr( tbspacetype,1,1) SPACETYPE , substr(E.SGNAME,1,20) STOGNAME , case when E.SGNAME is null then 'NOT AUTOMATIC STORAGE' when E.SGNAME is not null then 'AUTOMATIC STORAGE' end STORAGE_Y_N from syscat.tablespaces E left outer join syscat.stogroups G on G.SGNAME = E.SGNAME where E.tbspace not like 'SYS% with ur
TBSPACE TEMPSPACE1 STSCUBE IBMDB2SAMPLEXML IBMDB2SAMPLEREL USERSPACE1 DMSTBS
3/23/2013

SPACETYPE STOGNAME S IBMSTOGROUP D IBMSTOGROUP D D D D IBMSTOGROUP IBMSTOGROUP IBMSTOGROUP -

STORAGE_Y_N AUTOMATIC STORAGE AUTOMATIC STORAGE AUTOMATIC STORAGE AUTOMATIC STORAGE AUTOMATIC STORAGE NOT AUTOMATIC STORAGE
7

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

SQL 3 : Whether the indexes are in different table space then data table space
select substr(tabschema||'.'||tabname,1,40) TABNAME ,substr(tbspace,1,20)TBSPACE , substr( index_tbspace,1,20) INDEX_TBSPACE from syscat.tables where tabschema not like 'SYS%' and tabname not like 'EXPL%' and tabname not like 'ADVISE%' and type in ('T','S') and INDEX_TBSPACE is null and tbspace in (select tbspace from syscat.tablespaces where tbspacetype <> 'S' ) with ur
TABNAME TBSPACE INDEX_TBSPACE

DB2INST1.CL_SCHED
DB2INST1.ADEFUSR DB2INST1.EMPMDC DB2INST1.PRODUCTSUPPLIER CUBE_SCHEMA.PPCL_CUBE_CUBENBR

USERSPACE1
USERSPACE1 IBMDB2SAMPLEREL IBMDB2SAMPLEXML STSCUBE

CUBE_SCHEMA.PPCL_TRAN_LOG

STSCUBE

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

SQL 1 : To get the names of tables having primary key and unique Index
SELECT type , substr(tabschema,1,10) TABSCHEMA, substr( tabname,1,20) TABNAME FROM syscat.tabconst WHERE type in ('P','U') with ur
TYPE U U U P P P P TABSCHEMA SYSTOOLS SYSTOOLS SYSTOOLS DB2INST1 DB2INST1 DB2INST1 DB2INST1 TABNAME POLICY HMON_ATM_INFO HMON_COLLECTION DEPARTMENT EMPLOYEE EMP_PHOTO EMP_RESUME

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

SQL 2 : How to get count of Total Number of Indexes and Last used indexes total number
select distinct substr(tabschema,1,15) TABSCHEMA, substr(tabname,1,35) TABNAME, count(*) TOTALINDEX, (select count(*) from syscat.indexes where lastused = '01/01/0001' and tabname = I.tabname and tabschema = I.tabschema) LASTUSEDSINCE01010001 from syscat.indexes I where tabname not like 'EXPLAIN%' and tabschema not like 'SYS%' group by tabschema,tabname with ur
TABSCHEMA CUBE_SCHEMA DB2INST1 DB2INST1 DB2INST1 DB2INST1 DB2INST1 DB2INST1 DB2INST1 TABNAME PPCL_CUBE_CUBENBR DEPARTMENT INVENTORY ACT EMPLOYEE SUPPLIERS PRODUCT CUSTOMER TOTALINDEX 2 3 1 2 2 3 7 12 LASTUSEDSINCE01010001 0 0 1 1 1 3 5 7

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

10

SQL 1 : Bufferpool Hit Ratio Calculation


SELECT DBPARTITIONNUM PARTITION, SUBSTR(BP_NAME,1,20) BUFFERPOOL, (POOL_DATA_L_READS - POOL_DATA_P_READS) * 100 / (POOL_DATA_L_READS + 1) HIT_RATIO FROM SYSIBMADM.SNAPBP with ur

PARTITION

BUFFERPOOL

HIT_RATIO

0 IBMDEFAULTBP
0 BP08 0 IBMSYSTEMBP4K

99
97 0

0 IBMSYSTEMBP8K
0 IBMSYSTEMBP16K 0 IBMSYSTEMBP32K

0
0 0

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

11

SQL 2 : Status of Bound Packages


SELECT substr(PKGSCHEMA,1,12) PKGSCHEMA , substr(PKGNAME,1,10) PKGNAME, substr(BOUNDBY,1,8) BOUNDBY, VALID, ISOLATION, BLOCKING, DEGREE, INTRA_PARALLEL, VALIDATE, REOPTVAR FROM SYSCAT. PACKAGES WHERE PKGSCHEMA like 'DB2INST% with ur
PKGSCHEMA PKGNAME BOUNDBY VALID ISOLATION BLOCKING DB2INST1 P336011799 DB2INST1 N CS U DB2INST1 DB2INST1 P214731033 DB2INST1 X P132507749 DB2INST1 X CS CS U U INTRA_PA DEGREE RALLEL VALIDATE REOPTVAR 1N B N 1N 1N R B N N

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

12

SQL 3 : Status of missing MQT


select tabschema||'.'|| tabname || ' Is configured to have replicated MQT but is missing' from syscat.tables where tabschema = 'ACEDBA' and partition_mode <> 'R' and tabname not in ('CUSTOMER_DIM') and tbspace in (select tbspace from syscat.tablespaces where DBPGNAME = 'DBPG_1') and tabname not in (select bname from syscat.tabdep where bschema = 'ACEDBA' and dtype = 'S' and btype = 'T' ) with ur
ACEDBA.TIME_DIM Is configured to have replicated MQT but is missing
3/23/2013 DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc 13

Thanks
My contact and blog info : Renu Sharma ACE DBA Consulting Inc www.db2dbas.com renusharma@db2dbas.com, renusharma@aol.com 732-342-7630, 732-995-9963,732-374-3601 Facebook :https://www.facebook.com/home.php#!/pages/ACE-DBAConsulting/138802816289257 Twitter : @db2_dbas Linkedin : http://www.linkedin.com/home?trk=hb_tab_home_top

3/23/2013

DB2's GOT TALENT FINALS #3 BY Renu Sharma ACE DBA CONSULTING Inc

14