Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 30 Apr 2008 @ 10:29:37 GMT


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


Subj:   Re: Help in a procedure: Counting rows
 
From:   Murali.Deenadayalan

Hi,

Here is the exact one for your requirement:-

     CREATE SET TABLE rowcount2 ,NO FALLBACK ,
           NO BEFORE JOURNAL,
           NO AFTER JOURNAL,
           CHECKSUM = DEFAULT
           (
            DATABASE_NAME VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC,
            TABLE_NAME VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC,
            REC_COUNT BIGINT)
     PRIMARY INDEX (DATABASE_NAME,TABLE_NAME);


     REPLACE PROCEDURE load_rowcount (IN prm_database_name VARCHAR(30))
     BEGIN

        DECLARE var_table_name VARCHAR(50) ;
        DECLARE crsr_tables CURSOR FOR

           SELECT tablename FROM dbc.tables

           WHERE databasename= prm_database_name AND tablekind='T'
     ;
        OPEN crsr_tables;

     CURSOR_LOOP1:

     LOOP
        FETCH crsr_tables  INTO var_table_name;
        IF (SQLSTATE = '02000') THEN
           LEAVE CURSOR_LOOP1;
        END IF;

        CALL DBC.SysExecSql( 'INSERT INTO '  || prm_database_name
                  || '.' ||       'rowcount2  (DATABASE_NAME,TABLE_NAME,REC_COUNT) '
                  || ' SELECT '|| '''' || prm_database_name  || ''''|| ','
                  || '''' || var_table_name  || '''' || ',COUNT(*) FROM ' ||

           prm_database_name  || '.' || var_table_name || ';' );

     END LOOP CURSOR_LOOP1;
     CLOSE crsr_tables;

     END;

Thanks & Regards

Murali D.
Teradata Certified Application Developer V2R5



     
  <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