|
|
Archives of the TeradataForum
Message Posted: Wed, 30 Apr 2008 @ 10:29:37 GMT
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
| |