dotConnect for Snowflake provides the GetSchema method for getting Snowflake metadata. The method lets you read schema information without writing queries and parsing the output: it returns information on schemas, tables, views, columns, and keys in an easy-to-process format. The method is introduced in System.Data.Common.DbConnection.
The metadata is read from the INFORMATION_SCHEMA views and with the SHOW commands of the database specified in the Database connection string parameter. Objects of the INFORMATION_SCHEMA schema itself are not returned.
The GetSchema method is available in three overloads. All overloads return a System.Data.DataTable object that contains information about schema elements.
If you call the GetSchema method without parameters, or with the single parameter "MetaDataCollections" (which is actually the same), the method returns the list of metadata collections. The first column of every row is a collection name that you can pass to the method as the collectionName argument. The second column is the number of restrictions for this collection.
GetSchema with one argument returns general information about the collection queried. For example, GetSchema("Tables") returns the list of the tables in the current schema of the session if the Schema connection string parameter is specified, or in all schemas of the database if Schema is not specified.
In this overload, the first parameter is the name of a collection, and the second parameter is an array of restrictions that specify which subset of the collection is returned. The first restriction of every collection, except the ones that have no restrictions, is the schema name, followed by the table name and the column or key name. A null restriction value means that no restriction is applied. If the second parameter is null/Nothing, it is ignored.
Note the following when you specify restrictions:
CREATE TABLE employees.Instead of specifying the metadata collection name as a string constant, you can use the members of System.Data.Common.DbMetaDataCollectionNames and Devart.Data.Snowflake.SnowflakeMetaDataCollectionNames as the first GetSchema argument value. The members of these classes are string fields; each field stores the corresponding metadata collection name. This allows misspellings to be caught at compile time and enables IntelliSense to suggest all available metadata collection names.
The following table provides detailed information on metadata collections that can be retrieved using the GetSchema method, and restrictions that can be applied for them.
Collection Name |
Number of restrictions |
Return value |
Restriction descriptions |
|---|---|---|---|
| MetaDataCollections | 0 | Returns the list of metadata collections. | |
| DataSourceInformation | 0 | Returns information about the data source, for example, the product name and version. | |
| DataTypes | 0 | Returns information about the data types that the provider supports. | |
| Restrictions | 0 | Returns the restrictions of every metadata collection. | |
| ReservedWords | 0 | Returns the list of reserved words. | |
| Schemas | 1 | Returns the list of schemas in the database. |
|
| Tables | 2 | Returns the list of tables. By default, views (the VIEW table type) are not included; use the Views collection to get them, or set the table type restriction to ALL. Tables of other types, such as materialized views and external tables, are returned by default. |
|
| Views | 2 | Returns the list of views. |
|
| Columns | 3 | Returns the list of columns of tables and views. |
|
| PrimaryKeys | 3 | Returns the list of primary keys. |
|
| PrimaryKeyColumns | 3 | Returns the list of primary key columns. |
|
| UniqueKeys | 3 | Returns the list of unique keys. |
|
| UniqueKeyColumns | 3 | Returns the list of unique key columns. |
|
| ForeignKeys | 6 | Returns the list of foreign keys. |
|
| ForeignKeyColumns | 6 | Returns the list of foreign key columns. |
|
For standard tables, Snowflake stores the definitions of primary, unique, and foreign keys but doesn't enforce them. The key collections return these definitions.
The tables below list the columns of the collections with their names in the case in which dotConnect for Snowflake returns them: most of the names are in uppercase. The DataTable and DataRow classes find columns by name case-insensitively, so, for example, row["Name"] and row["NAME"] return the same value.
Schemas
Column Name | Description |
|---|---|
| NAME | The name of the schema. |
| OWNER | The role that owns the schema. |
| ISTRANSIENT | Indicates whether the schema is transient. |
| ISMANAGEDACCESS | Indicates whether the schema is a managed access schema. |
| RETENTIONTIME | The number of days that historical data is retained for Time Travel. |
| CREATED | The date and time when the schema was created. |
| LASTALTERED | The date and time when the schema was last altered. |
| COMMENT | The comment for the schema. |
Tables
Column Name | Description |
|---|---|
| SCHEMA | The name of the schema that contains the table. |
| NAME | The name of the table. |
| OWNER | The role that owns the table. |
| TYPE | The type of the table, for example, BASE TABLE or TEMPORARY TABLE. |
| ROWCOUNT | The number of rows in the table. |
| BYTES | The number of bytes accessed by a scan of the table. |
| ISTRANSIENT | Indicates whether the table is transient. |
| CLUSTERINGKEY | The clustering key of the table. |
| AUTOCLUSTERINGON | Indicates whether automatic clustering is enabled for the table. |
| RETENTIONTIME | The number of days that historical data is retained for Time Travel. |
| CREATED | The date and time when the table was created. |
| LASTALTERED | The date and time when the table was last altered. |
| COMMENT | The comment for the table. |
Views
Column Name | Description |
|---|---|
| SCHEMA | The name of the schema that contains the view. |
| NAME | The name of the view. |
| OWNER | The role that owns the view. |
| DEFINITION | The text of the query that defines the view. |
| ISSECURE | Indicates whether the view is secure. |
| CREATED | The date and time when the view was created. |
| LASTALTERED | The date and time when the view was last altered. |
| COMMENT | The comment for the view. |
Columns
Column Name | Description |
|---|---|
| SCHEMA | The name of the schema that contains the table or view. |
| Table | The name of the table or view. |
| NAME | The name of the column. |
| POSITION | The position of the column in the table, starting from 1. |
| NULLABLE | Indicates whether the column can contain NULL values. |
| DATATYPE | The Snowflake data type of the column, for example, TEXT, BOOLEAN, or TIMESTAMP_NTZ. NUMBER columns are returned as FIXED, and FLOAT columns are returned as REAL. |
| LENGTH | The maximum length of a text or binary column. For a BINARY column without a declared length, it is 8388608. For VARIANT, OBJECT, ARRAY, GEOGRAPHY, GEOMETRY, and VECTOR columns, it is 16777216. |
| Precision | The precision of a numeric column. For a FLOAT column, it is 38. |
| SCALE | The scale of a numeric column. For a FLOAT column, it is 19. For TIME, TIMESTAMP_NTZ, TIMESTAMP_LTZ, and TIMESTAMP_TZ columns, it is the precision of fractional seconds, from 0 to 9. |
| COLLATION | The collation of a text column. |
| Default | The default value of the column. |
| ISIDENTITY | Indicates whether the column is an identity column. |
| IDENTITYSTART | The start value of an identity column. |
| IDENTITYINCREMENT | The increment of an identity column. |
| COMMENT | The comment for the column. |
| ProviderType | The numeric representation of the System.Data.DbType value of the column. |
| NativeType | The numeric representation of the SnowflakeType value of the column. For more information, see Data Type Mapping. |
PrimaryKeys, UniqueKeys
Column Name | Description |
|---|---|
| SCHEMA | The name of the schema that contains the table. |
| Table | The name of the table. |
| NAME | The name of the constraint. |
| ISDEFERRABLE | Indicates whether the constraint is deferrable. |
| ISINITIALLYDEFERRED | Indicates whether the constraint is initially deferred. |
| ISENFORCED | Indicates whether the constraint is enforced. |
| CREATED | The date and time when the constraint was created. |
| LASTALTERED | The date and time when the constraint was last altered. |
| COMMENT | The comment for the constraint. |
PrimaryKeyColumns, UniqueKeyColumns
Column Name | Description |
|---|---|
| ConstraintName | The name of the constraint. |
| Schema | The name of the schema that contains the table. |
| Table | The name of the table. |
| Name | The name of the column. |
| Position | The position of the column in the key, starting from 1. |
| Created | The date and time when the constraint was created. |
| Comment | The comment for the constraint. |
ForeignKeys
Column Name | Description |
|---|---|
| CONSTRAINTNAME | The name of the foreign key. |
| SCHEMA | The name of the schema that contains the foreign key. |
| Table | The name of the table that contains the foreign key. |
| REFERENCEDCONSTRAINTNAME | The name of the primary or unique key that the foreign key references. |
| REFERENCEDSCHEMA | The name of the schema that contains the referenced key. |
| REFERENCEDTABLE | The name of the table that contains the referenced key. |
| MATCHOPTION | The match option of the foreign key. |
| UPDATERULE | The update rule of the foreign key. |
| DELETERULE | The delete rule of the foreign key. |
| CREATED | The date and time when the foreign key was created. |
| LASTALTERED | The date and time when the foreign key was last altered. |
| COMMENT | The comment for the foreign key. |
ForeignKeyColumns
Column Name | Description |
|---|---|
| ConstraintName | The name of the foreign key. |
| Schema | The name of the schema that contains the table. |
| Table | The name of the table. |
| Name | The name of the foreign key column. |
| Position | The position of the column in the foreign key, starting from 1. |
| ReferencedConstraintName | The name of the referenced primary or unique key. |
| ReferencedSchema | The name of the schema that contains the referenced table. |
| ReferencedTable | The name of the referenced table. |
| ReferencedColumn | The name of the referenced column. |
| UpdateRule | The update rule of the foreign key. |
| DeleteRule | The delete rule of the foreign key. |
| Deferrability | The deferrability of the foreign key. |
| Created | The date and time when the foreign key was created. |
| Comment | The comment for the foreign key. |
The following code sample shows how to get the list of columns of the EMPLOYEES table in the PUBLIC schema and print the name and data type of each column.
The following code sample gets all tables whose names start with ORDER in all schemas of the database. The schema restriction is set to "%", so that the Schema connection string parameter is not applied.