Information schema
Applies to: Databricks SQL Databricks Runtime 10.4 LTS and above Unity Catalog only
The INFORMATION_SCHEMA
is a SQL standard based schema, provided in every catalog created on Unity Catalog.
Within the information schema, you can find a set of views describing the objects known to the schema’s catalog that you are privileged to see.
The information schema of the SYSTEM
catalog returns information about objects across all catalogs within the metastore. Information schema system tables do not contain metadata about hive_metastore
objects.
The purpose of the information schema is to provide a SQL based, self describing API to the metadata.
Entity relationship diagram of the information schema
The following entity relationship (ER) diagram provides an overview of a subset of information schema views and how they relate to each other.
Information schema views
Name |
Description |
---|---|
Lists principals that have privileges on the catalogs. |
|
Describes provider share mounted onto catalogs. |
|
Contains tags that have been applied to the catalogs. |
|
Describes catalogs. |
|
Reserved for future use. |
|
Describes column masks on table columns in the catalog. |
|
Contains column tagging metadata within a table. |
|
Describes columns of tables and views in the catalog. |
|
Lists principals that have privileges on the foreign connections. |
|
Describes foreign connections. |
|
Describes the constraints referencing columns in the catalog. |
|
Describes the constraints referencing tables in the catalog. |
|
Lists principals that have privileges on the credentials. |
|
Describes credentials. |
|
Lists principals that have privileges on the external locations. |
|
Describes external locations. |
|
Returns the name of this information schema’s catalog. |
|
Lists the columns of the primary or foreign key constraints within the catalog. |
|
Lists principals that have privileges on the current metastore. |
|
Describes the current metastore. |
|
Describes parameters of routines (functions) in the catalog. |
|
Describes providers. |
|
Lists allowed IP ranges for recipients. |
|
Lists tokens for recipients. |
|
Describes recipients. |
|
Describes referential (foreign key) constraints defined in the catalog. |
|
Describes result columns of table valued functions. |
|
Lists principals that have privileges on the routines in the catalog. |
|
Describes routines (functions) in the catalog. |
|
Describes row filters on tables in the catalog. |
|
Lists principals that have privileges on the schemas in the catalog. |
|
Contains schema tagging metadata within the schema. |
|
Describes the schemas referenced in shares. |
|
Describes schemas within the catalog. |
|
Describes the recipients granted access to shares. |
|
Describes shares. |
|
[Deprecated] Lists principals that have privileges on the storage credentials. |
|
[Deprecated] Describes storage credentials. |
|
Describes metadata for all primary and foreign key constraints within the catalog. |
|
Lists principals that have privileges on the tables and views in the catalog. |
|
Describes the tables referenced in shares. |
|
Contains table tagging metadata within a table. |
|
Describes tables and views defined within the catalog. |
|
Describes view specific information about the views in the catalog. |
|
Describes volumes defined in the catalog. |
|
Lists principals that have privileges on the volumes in the catalog. |
|
Contains volume tagging metadata applied to a volume. |
Notes
While identifiers are case-insensitive when referenced in SQL statements, they are stored in the information schema as STRING
.
This implies that you must either search for them using the case in which the identifier is stored, or use functions such as ilike.
Examples
> SELECT table_name, column_name
FROM information_schema.columns
WHERE data_type = 'DOUBLE'
AND table_schema = 'information_schema';
The following are examples of workflows that use the system level information schema tables.
If you want to view all tables that have been created in the last 24 hours, your query could look like the following.
> SELECT table_name, table_owner, created_by, last_altered, last_altered_by, table_catalog
FROM system.information_schema.tables
WHERE datediff(now(), last_altered) < 1;
If you want to view how many tables you have in each schema, consider the following example.
> SELECT table_schema, count(table_name)
FROM system.information_schema.tables
WHERE table_schema = 'tpch'
GROUP BY table_schema
ORDER BY 2 DESC