dbo.fSQLStatistics
This function returns as a result set a list of statistics about a table and the indexes associated with the table.
Syntax
dbo.fSQLStatistics (<'
database_qualifier
' | null>, <'
table_name
' | null>, <'
unique
' | null>)
Arguments
Table 122
dbo.fSQLStatistics Arguments
Parameter
Type
Default Value
Description
database_qualifier
VARCHAR
Current database
Name of the database from which the details are to be obtained
table_name
VARCHAR
(no default value)
Name of the table whose column information is required. Pattern matching is supported (see
String Search Patterns
).
unique
SMALLINT
(no default value)
Type of index:
0 = SQL_INDEX_UNIQUE
1 = SQL_INDEX_ALL
Returned Result Set
Table 123
dbo.fSQLStatistics Returned Result Set
Column Name
Data Type
Description
TABLE_QUALIFIER
VARCHAR
Name of the database containing the table to which the statistic or index applies; NULL if not applicable to the database.
TABLE_OWNER
VARCHAR
Schema name of the table to which the statistic or index applies; NULL if not applicable to the database.
TABLE_NAME
VARCHAR not NULL
Name of the table to which the statistic or index applies
NON_UNIQUE
SMALLINT
Indicates whether the index does not allow duplicate values:
•
0 = SQL_FALSE if the index values must be unique.
•
1 = SQL_TRUE if the index values can be nonunique.
NULL is returned if TYPE is SQL_TABLE_STAT.
INDEX_QUALIFIER
VARCHAR
The identifier that is used to qualify the index name doing a DROP INDEX; NULL is returned if an index qualifier is not supported by the database or if TYPE is SQL_TABLE_STAT.
INDEX_NAME
VARCHAR
Index name; NULL is returned if TYPE is SQL_TABLE_STAT.
TYPE
SMALLINT not NULL
Type of information being returned:
•
0 = SQL_TABLE_STAT
•
3 = SQL_INDEX_OTHER
SEQ_IN_INDEX
SMALLINT
Column sequence number in index (starting with 1). NULL is returned if TYPE is SQL_TABLE_STAT.
COLUMN_NAME
VARCHAR
Column name. If the column is based on an expression, such as PERSONID + NAME, the expression is returned. Iff the expression cannot be determined, an empty string is returned.
NULL is returned if TYPE is SQL_TABLE_STAT.
COLLATION
CHAR
Sort sequence for the column:
A = ascending
D = descending
NULL is returned if column sort sequence is not supported by the database or if TYPE is SQL_TABLE_STAT.
CARDINALITY
INTEGER
Cardinality of table or index.
Number of rows in table if TYPE is SQL_TABLE_STAT. Number of unique values in the index if TYPE is not SQL_TABLE_STAT
NULL is returned if the value is not available from the database.
PAGES
INTEGER
Number of pages used to store the index or table.
Number of pages for the table if TYPE is SQL_TABLE_STAT. Number of pages for the index if TYPE is not SQL_TABLE_STAT
NULL is returned if the value is not available from the database or if not applicable to the database.
FILTER_CONDITION
VARCHAR
If the index is a filtered index, this is the filter condition, such as CLASSID > 150. If the filter condition cannot be determined, this is an empty string.
NULL if the index is not a filtered index, it cannot be determined whether the index is a filtered index, or TYPE is SQL_TABLE_STAT.
Example
This example returns statistics about all indexes for all tables that begin with the letter "c" in the default DEMODATA sample database. NULLs are excluded from INDEX_NAME. See also
String Search Patterns
.
SELECT * FROM dbo.fSQLStatistics ('Demodata', 'c%', 1) WHERE INDEX_NAME IS NOT NULL
Result Set
(abbreviated for space considerations):
TABLE_NAME INDEX_NAME COLUMN_NAME
========== ================ ====================
Class UK_ID ID
Class Class_Name Name
Class Class_Name Section
Class Class_seg_Faculty Faculty_ID
Class Class_seg_Faculty Start_Date
Class Class_seg_Faculty Start_Time
Class Building_Room Building_Name
Class Building_Room Room_Number
Class Building_Room Start_Date
Class Building_Room Start_Time
Course Course_Name Name
Course DeptName Dept_Name
12 rows were affected.