Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 14 Mar 2006 @ 18:07:13 GMT


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


Subj:   Re: SQL to display tables and their total record count
 
From:   Geoffrey Rommel

  Is it possible to display tables name and their rowcounts in a sql query..  


Terry's reply gave me the idea of doing this in Perl. You're gonna love this!

     #!/usr/bin/perl
     use Teradata::SQL;

     $DB = shift;
     die "Please specify a database\n" unless $DB;

     # TDLOGON is an environment var containing the logon string.
     $dbh = Teradata::SQL::connect($ENV{'TDLOGON'})
      or die "Could not connect";

     # You'll get a result only if at least one column has statistics.
     $clist = $dbh->open("select TableName, min(ColumnName)
      from DBC.ColumnStats
      where DatabaseName='$DB'
      and FieldStatistics is not null
      group by TableName
      order by 1") or die "Could not prepare query";
     while (@tcol = $clist->fetchrow_list) {
        $sth = $dbh->open("help statistics $DB.$tcol[0] column $tcol[1]");
        @stats = $sth->fetchrow_list;
        printf "%-32s %15.0f\n", $tcol[0], $stats[2];
        $sth->close;
     }
     $clist->close;


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023