SQLColumns

SQLColumns returns SQL_SUCCESS whether or not values exist for the CatalogName, TableName, or ColumnName parameters. SQLFetch returns SQL_NO_DATA when invalid values are used in these parameters.

Note

For large value types, all length parameters will be returned with a value of SQL_SS_LENGTH_UNLIMITED.

SQLColumns can be executed on a static server cursor. An attempt to execute SQLColumns on an updatable (dynamic or keyset) cursor will return SQL_SUCCESS_WITH_INFO indicating that the cursor type has been changed.

The SQL Native Client ODBC driver supports reporting information for tables on linked servers by accepting a two-part name for the CatalogName parameter: Linked_Server_Name.Catalog_Name.

For ODBC 2.x applications not using wildcards in TableName, SQLColumns returns information about any tables whose names match TableName and are owned by the current user. If the current user owns no table whose name matches the TableName parameter, SQLColumns returns information about any tables owned by other users where the table name matches the TableName parameter. For ODBC 2.x applications using wildcards, SQLColumns returns all tables whose names match TableName. For ODBC 3.x applications SQLColumns returns all tables whose names match TableName regardless of owner or whether wildcards are used.

The following table lists the columns returned by the result set:

Column name Description

DATA_TYPE

Returns SQL_VARCHAR, SQL_VARBINARY, or SQL_WVARCHAR for the varchar(max) data types.

TYPE_NAME

Returns “varchar”, “varbinary”, or “nvarchar” for the varchar(max), varbinary(max), and nvarchar(max) data types.

COLUMN_SIZE

Returns SQL_SS_LENGTH_UNLIMITED for varchar(max) data types indicating that the size of the column is unlimited.

BUFFER_LENGTH

Returns SQL_SS_LENGTH_UNLIMITED for varchar(max) data types indicating that the size of the buffer is unlimited.

SQL_DATA_TYPE

Returns SQL_VARCHAR, SQL_VARBINARY, or SQL_WVARCHAR for the varchar(max) data types.

CHAR_OCTET_LENGTH

Returns the maximum length of a char or binary column. Returns 0 to indicate that the size is unlimited.

SS_XML_SCHEMACOLLECTION_CATALOG_NAME

Returns the name of the catalog where an XML schema collection name is defined. If the catalog name cannot be found, then this variable contains an empty string.

SS_XML_SCHEMACOLLECTION_SCHEMA_NAME

Returns the name of the schema where an XML schema collection name is defined. If the schema name cannot be found, then this variable contains an empty string.

SS_XML_SCHEMACOLLECTION_NAME

Returns the name of an XML schema collection. If the name cannot be found, then this variable contains an empty string.

SS_UDT_CATALOG_NAME

The name of the catalog containing the UDT (user-defined type).

SS_UDT_SCHEMA_NAME

The name of the schema containing the UDT.

SS_UDT_ASSEMBLY_TYPE_NAME

The assembly-qualified name of the UDT.

For UDTs, the existing TYPE_NAME column is used to indicate the name of the UDT; therefore no additional column for it should be added to the result set of SQLColumns or SQLProcedureColumns. The DATA_TYPE for a UDT column or parameter is SQL_SS_UDT.

For the UDT of parameters, you can use the new driver-specific descriptors defined above to get or set the extra metadata properties of a UDT, should the server return or require this information.

See Also

Concepts

ODBC API Implementation Details

Other Resources

SQLColumns Function

Help and Information

Getting SQL Server 2005 Assistance