DB_Statistics Function

Action

Retrieves a list of statistics about a single table and the indexes that are associated with the table. The information is returned as a result set on the statement handle.

Syntax

hstmnt = DB_Statistics (hdbc, catalog-name, schema-name, table-name, unique, reserved)
Variable Description
hstmnt

The returned handle to the executed SQL statement. This is an input parameter for other DBTester functions, for example DB_FetchNext. HSQL.

hdbc

The handle to a database as returned by DB_Connect. HDATABASE.

catalog-name

Catalog name. STRING.

schema-name

String search pattern for schema names. STRING.

table-name

String search pattern for table names. STRING.

unique
Type of index.
  • "0" for SQL_INDEX_UNIQUE.
  • "1" for " SQL_INDEX_ALL.
STRING.
reserved
Indicates the importance of the Cardinality and Pages columns in the result set.
  • "0" for SQL_QUICK
  • "1" for " SQL_ENSURE
STRING.

Notes

  • DB_Statistics corresponds to SQLStatistics. For additional information about SQLStatistics, see SQLStatistics Function.
  • The table-name argument is required. It cannot be an empty string or contain a wildcard.
  • The following wildcard characters are supported for arguments:
    Wildcard character Matches
    % The percent sign matches any character sequence.
    _ The underscore matches any single character.
  • To omit a variable argument, which is not a required argument, specify the argument as an empty string ("").

  • The reserved argument can have one of the following values:
    Value Meaning Description
    "0" SQL_QUICK The Cardinality and Page columns are retrieved only if they are readily available from the server.
    "1" SQL_ENSURE The statistics are retrieved unconditionally.
  • When you receive a valid statement handle, you can call DB_FetchNext or DB_FetchPrevious to manipulate the information.

Example

[ ] STRING cat, sch, tab-name, ignore 
[ ] INTEGER i 
[ ] hstmnt = DB_Statistics (hdbc, cat, sch, "", "1", "0") 
[ ] // retrieve name of table to which stats apply and whether ix is unique; // ignore the rest.
[-] while (DB_FetchNext (hstmt, ignore, ignore, tab-name, i) == TRUE) {
	[ ] //print table names and index info ... 
[ ] }