Applies To: SQL Server 2014, SQL Server 2016 Preview
Returns the column information, one row per column, for the specified linked server tables. sp_columns_ex returns column information for only the specific column if column is specified.
Applies to: SQL Server (SQL Server 2008 through current version).
sp_columns_ex [ @table_server = ] 'table_server' [ , [ @table_name = ] 'table_name' ] [ , [ @table_schema = ] 'table_schema' ] [ , [ @table_catalog = ] 'table_catalog' ] [ , [ @column_name = ] 'column' ] [ , [ @ODBCVer = ] 'ODBCVer' ]
- [ @table_server = ] 'table_server'
Is the name of the linked server for which to return column information. table_server is sysname, with no default.
- [ @table_name = ] 'table_name'
Is the name of the table for which to return column information. table_name is sysname, with a default of NULL.
- [ @table_schema = ] 'table_schema'
Is the schema name of the table for which to return column information. table_schema is sysname, with a default of NULL.
- [ @table_catalog = ] 'table_catalog'
Is the catalog name of the table for which to return column information. table_catalog is sysname, with a default of NULL.
- [ @column_name = ] 'column'
Is the name of the database column for which to provide information. column is sysname, with a default of NULL.
- [ @ODBCVer = ] 'ODBCVer'
Is the version of ODBC that is being used. ODBCVer is int, with a default of 2. This indicates ODBC Version 2. Valid values are 2 or 3. For information about the behavior differences between versions 2 and 3, see the ODBC SQLColumns specification.
Table or view qualifier name. Various DBMS products support three-part naming for tables (qualifier.owner.name). In SQL Server this column represents the database name. In some products, it represents the server name of the table's database environment. This field can be NULL.
Table or view owner name. In SQL Server, this column represents the name of the database user that created the table. This field always returns a value.
Table or view name. This field always returns a value.
Column name, for each column of the TABLE_NAME returned. This field always returns a value.
Integer value that correspond to ODBC type indicators. If this is a data type that cannot be mapped to an ODBC type, this value is NULL. The native data type name is returned in the TYPE_NAME column.
String representing a data type. The underlying DBMS presents this data type name.
Number of significant digits. The return value for the PRECISION column is in base 10.
Transfer size of the data.1
Number of digits to the right of the decimal point.
Is the base for numeric data types.
1 = NULL is possible.
0 = NOT NULL.
This field always returns NULL.
Default value of the column.
Value of the SQL data type as it appears in the TYPE field of the descriptor. This column is the same as the DATA_TYPE column, except for the datetime and SQL-92 interval data types. This column always returns a value.
Subtype code for datetime and SQL-92 interval data types. For other data types, this column returns NULL.
Maximum length in bytes of a character or integer data type column. For all other data types, this column returns NULL.
Ordinal position of the column in the table. The first column in the table is 1. This column always returns a value.
Nullability of the column in the table. ISO rules are followed to determine nullability. An ISO SQL-compliant DBMS cannot return an empty string.
YES = Column can include NULLS.
NO = Column cannot include NULLS.
This column returns a zero-length string if nullability is unknown.
The value returned for this column is different from the value returned for the NULLABLE column.
SQL Server data type, used by extended stored procedures.
For more information, see the Microsoft ODBC documentation.
sp_columns_ex is executed by querying the COLUMNS rowset of the IDBSchemaRowset interface of the OLE DB provider corresponding to table_server. The table_name, table_schema, table_catalog, and column parameters are passed to this interface to restrict the rows returned.
sp_columns_ex returns an empty result set if the OLE DB provider of the specified linked server does not support the COLUMNS rowset of the IDBSchemaRowset interface.
Requires SELECT permission on the schema.
sp_columns_ex follows the requirements for delimited identifiers. For more information, see Database Identifiers.
The following example returns the data type of the JobTitle column of the HumanResources.Employee table in the AdventureWorks2012 database on the linked server Seattle1.
EXEC sp_columns_ex 'Seattle1', 'Employee', 'HumanResources', 'AdventureWorks2012', 'JobTitle';