Personal tools
You are here: Home Forums DB2 Script for null
Navigation
Log in


Forgot your password?
 
Document Actions

Script for null

Up to DB2

Script for null

Posted by santhosh babu at July 17. 2008

nedd a script for null checking in the database. The following is the format I am expecting.


 


 


Table Name                               Column Name                Total Records in Table                Null Records for this column


------------------------                        --------------------------          ---------------------------------------         -----------------------------------------


Emp                                           Empno                          300                                           50


 


Re: Script for null

Posted by Saurabh at August 21. 2008

1. Easy way:


In DB2 9.5, use this query " select substr(a.tabname,1,30) as tabname,substr(a.COLNAME,1,30) as colname,b.card,a.NUMNULLS from syscat.columns a, syscat.tables b where a.tabname = b.tabname and a.TABSCHEMA = b.TABSCHEMA "


2. Hard way:


Consider this table,


A
-----------
          1
          2
          3
          4
          -
          1
          2
          3
          4
          -
          1
          2
          3
          4
          -

  15 record(s) selected.


Issuing the query " select x.a,x.cnt,x.sumcnt from (select a,count(1) as cnt ,sum(count(1)) over() as sumcnt from sj1  group by a) as x where x.a is null "

A           CNT         SUMCNT
----------- ----------- -----------
          -           3          15

  1 record(s) selected.


You can use this to create a script.






OR,


Re: Script for null

Posted by Saurabh at August 21. 2008

Oh, just one more thing, for the first query to give you a good result, ensure that your statistics are updated.


Powered by Ploneboard
Security Awareness
Would you like your company to implement gamification into your security awareness program?





Polls