Record Count / Are there any records in table

Cool_Dude_eh

New Member
Hello,
I am looking for a quick way to go through every table in a database and determine if there are any records in the table for dump and load purposes.
(not necessarily a count, just is there 1 or more records)

I have read quite a bit about people attempting to count how many records are in tables, but I have not found a clear answer.
If only something like this would work.
Anyone have any ideas?

[FONT=r_ansi]output to loadlist.txt.
def var i as int init 0.

for each _file where _file-number > 0:
for each value(_file-name):
/* _file-name is field in _file with table name */
i = i + 1.
if i > 1 then
do:
display _file-name.
i = 0.
/* more code here ..... */
next.
end.
end.
end.
[/FONT]
 

Casper

ProgressTalk.com Moderator
Staff member
It gives an analysis of the database. Including record counts of all the tables.

Since you only want to know if there is a record in a table I guess the following example will work fine for you:

Code:
DEFINE STREAM sResults.
 
DEFINE VARIABLE hQuery AS HANDLE     NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE     NO-UNDO.
 
OUTPUT STREAM sResults TO filledtables.txt.
 
FOR EACH _file WHERE _file._hidden = NO:
    CREATE QUERY hQuery.
    CREATE BUFFER hBuffer FOR TABLE _file._file-name.
    hQuery:ADD-BUFFER(hBuffer).
    hQuery:QUERY-PREPARE('for each ' + hBuffer:TABLE).
    hQuery:QUERY-OPEN().
    hQuery:GET-FIRST().
    IF NOT hQuery:QUERY-OFF-END
    THEN PUT STREAM sResults UNFORMATTED _file._file-name SKIP.
 
    DELETE OBJECT hBuffer.
    DELETE OBJECT hQuery.
 
END.
 
OUTPUT STREAM sResults CLOSE.

HTH,

Casper.
 

tamhas

ProgressTalk.com Sponsor
Try it ... you will get lots of information with very little effort. Samples of output are in the documentation.

It's fast too.
 

Cool_Dude_eh

New Member
Thanks for the responses everyone.
Casper - I will give your code a try and see.

I should have said in my original post "besides db analysis"

The reason for this is as follows.
During dump and load.
Dump goes great .... 700+ tables around an hour.
Great so far.
Now time to bulk load.
Say we have data in 300 out of 700 tables.
If your load scripts has every table, progress seems to take a little more than a minute for a table with no data.
(To me it seems like we do this to handle a progress issue)
You multiple that by 400 and you have 6+ hours of wasted time.
So we have a custom load scripts that loads only tables with data.
We have a spreadsheet that we copy a db analysis couumn into that highlights tables that went from zero records to any positive number of records.
Then we manually maintain this load script.
This is in v9.1e and was same in v8.3b
I use similar code as in first post to create binary dump scripts.
Would like to do the same for load scripts.
 
Top