SQLColumns

 

System_CAPS_ICON_warning.jpg Warning

SQL Server Native Client (SNAC) is not supported beyond SQL Server 2012. Avoid using SNAC in new development work, and plan to modify applications that currently use it. The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows to Microsoft SQL Server and Microsoft Azure SQL Database.

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.

System_CAPS_ICON_note.jpg 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 Server 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 nameDescription
DATA_TYPEReturns SQL_VARCHAR, SQL_VARBINARY, or SQL_WVARCHAR for the varchar(max) data types.
TYPE_NAMEReturns “varchar”, “varbinary”, or “nvarchar” for the varchar(max), varbinary(max), and nvarchar(max) data types.
COLUMN_SIZEReturns SQL_SS_LENGTH_UNLIMITED for varchar(max) data types indicating that the size of the column is unlimited.
BUFFER_LENGTHReturns SQL_SS_LENGTH_UNLIMITED for varchar(max) data types indicating that the size of the buffer is unlimited.
SQL_DATA_TYPEReturns SQL_VARCHAR, SQL_VARBINARY, or SQL_WVARCHAR for the varchar(max) data types.
CHAR_OCTET_LENGTHReturns the maximum length of a char or binary column. Returns 0 to indicate that the size is unlimited.
SS_XML_SCHEMACOLLECTION_CATALOG_NAMEReturns 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_NAMEReturns 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_NAMEReturns the name of an XML schema collection. If the name cannot be found, then this variable contains an empty string.
SS_UDT_CATALOG_NAMEThe name of the catalog containing the UDT (user-defined type).
SS_UDT_SCHEMA_NAMEThe name of the schema containing the UDT.
SS_UDT_ASSEMBLY_TYPE_NAMEThe 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.

When a client connects to SQL Server and calls SQLColumns, using NULL or wild card values for the catalog input parameter will not return information from other catalogs. Instead, only information about the current catalog will be returned. The client can first call SQLTables to determine in which catalog the desired table is located. The client can then use that catalog value for the catalog input parameter in its call to SQLColumns to retrieve information about the columns in that table.

The result set returned by SQLColumns depends on the setting of SQL_SOPT_SS_NAME_SCOPE. For more information, see SQLSetStmtAttr. The following columns have been added for table-valued parameters:

Column nameData typeContents
SS_IS_COMPUTEDSmallintFor a column in a TABLE_TYPE, this is SQL_TRUE if the column is a computed column; otherwise, SQL_FALSE.
SS_IS_IDENTITYSmallintSQL_TRUE if the column is an identity column; otherwise, SQL_FALSE.

For more information about table-valued parameters, see Table-Valued Parameters (ODBC).

For information about the values returned for date/time types, see Catalog Metadata.

For more information, see Date and Time Improvements (ODBC).

SQLColumns supports large CLR user-defined types (UDTs). For more information, see Large CLR User-Defined Types (ODBC).

Two SQL Server specific columns have been added to the result set for SQLColumns:

Column nameData typeDescription
SS_IS_SPARSESmallintIf the column is a sparse column, this is SQL_TRUE; otherwise, SQL_FALSE.
SS_IS_COLUMN_SETSmallintIf the column is the column_set column, this is SQL_TRUE; otherwise, SQL_FALSE.

In conformance with the ODBC specification, SS_IS_SPARSE and SS_IS_COLUMN_SET appear before all driver-specific columns that were added to SQL Server versions earlier than SQL Server 2008, and after all columns mandated by ODBC itself.

The result set returned by SQLColumns depends on the setting of SQL_SOPT_SS_NAME_SCOPE. For more information, see SQLSetStmtAttr.

For more information about sparse columns in ODBC, see Sparse Columns Support (ODBC).

SQLColumns Function
ODBC API Implementation Details

Community Additions

ADD
Show: