Tech Tips
Is there a quick, low-impact way to determine whether
a Teradata table is empty or if it contains rows and
you don't always know the column names or indexes?
You came to the right place for help on this. Next
time you need to know whether a table is empty or not,
try this:
SELECT 1 from table_name SAMPLE 1;
If the table contains rows, the statement will return
immediately after sampling one row from the table. If
the table is empty, you will get an indication that
no rows were found.
What SAMPLE n does is take the value specified by "n"
and dip randomly into the table to select "randomly"
that number of rows. Because you do not care about having
meaningful data returned, "1" is selected
in this example just to provide something as the object
of the SELECT and to eliminate spool file processing.
This query will be as short in duration whether the
table contains rows or not.
|