Article ID: 203638 - Last Review: February 2, 2005 - Revision: 3.4 How to return information about SQL Server linked serversThis article was previously published under Q203638 SUMMARY
SQL Server 7.0 and later versions of SQL Server allow the addition of external data sources as linked servers. This feature provides access to distributed, heterogeneous queries against OLE DB data sources. When connecting to SQL Server, a cursor listing available tables can be returned with the SQLTables(file_handle) command. The SQLTables() command, however, does not return information about tables available in Linked Servers. Information regarding linked servers is returned by three different SQL Server stored procedures. This article describes how to use those stored procedures to return information regarding tables available from Linked Servers.
MORE INFORMATION
SQL Server linked servers are defined as mappings against a specific linked server. Therefore, a linked server may not necessarily be part of a SQL Server database. SQL Server linked servers are defined using the sp_addlinkedserver system stored procedure. The linked server definition contains all the information needed to locate the OLE DB data source. Remote tables from the linked server name can then be referenced in two ways:
sp_linkedservers returns the following columns:
SRV_NAME Name of the linked server.
SRV_PROVIDERNAME Friendly name of the OLE DB provider managing
access to the specified linked server.
SRV_PRODUCT Product name of the linked server.
SRV_DATASOURCE OLE DB datasource property corresponding to the
specified linked server.
SRV_PROVIDERSTRING OLE DB provider string property corresponding to
the specified linked server.
SRV_LOCATION OLE DB location property corresponding to the
specified linked server.
SRV_CAT OLE DB catalog property corresponding to the
specified linked server.
TABLE_SERVER Name of the linked server for which to return table
information, with no default.
TABLE_NAME Name of the table for which to return data type
information, with a default of NULL.
TABLE_SCHEMA Is the table schema, with a default of NULL.
TABLE_CATALOG Catalog Name of the database in which the specified
table resides, with a default of NULL.
TABLE_TYPE Type of the table to return, with a default of NULL.
sp_tables_ex returns the following columns: TABLE_CAT Table qualifier name. (May be null) TABLE_SCHEM Table or view owner name. TABLE_NAME Table name. TABLE_TYPE Table, system table, or view. REMARKS SQL Server does not return a value for this column. sp_columns_ex returns column information, one row per column, for the given linked server table(s). sp_columns_ex returns column information only for the given column if column is specified. This stored procedure accepts the following arguments:
TABLE_SERVER Name of the linked server for which to return column
information, with no default.
TABLE_NAME Name of the table for which to return column
information, with a default of NULL.
TABLE_SCHEMA Name of the table for which to return column
information, with a default of NULL.
TABLE_CATALOG Catalog name of the table for which to return column
information, with a default of NULL.
COLUMN Name of the database column for which to provide
information, with a default of NULL.
ODBCVer The version of ODBC being used. ODBCVer is an
integer, with a default value of 2, indicating ODBC
Version 2. Valid values are 2 or 3.
sp_columns_ex returns the following columns:
TABLE_CAT Table or view qualifier name. (May be null)
TABLE_SCHEM Table or view owner name.
TABLE_NAME Table or view name.
COLUMN_NAME Column name, for each column of the specified table.
DATA_TYPE Integer value corresponding to ODBC type indicators.
TYPE_NAME String representing a data type.
COLUMN_SIZE Number of significant digits.
BUFFER_LENGTH Transfer size of the data.
DECIMAL_DIGITS Number of digits to the right of the decimal point.
NUM_PREC_RADIX Is the base for numeric data types.
NULLABLE Specifies nullability.
REMARKS This field always returns NULL.
COLUMN_DEF Default value of the column.
SQL_DATA_TYPE Value of the SQL data type as it appears in the TYPE
field of the descriptor.
SQL_DATETIME_SUB Subtype code for datetime and SQL-92 interval data
types. For other data types, this column returns
NULL.
CHAR_OCTET_LENGTH Maximum length in bytes of a character or integer
data type column. For all other data types, this
column returns NULL.
ORDINAL_POSITION Ordinal position of the column in the table.
IS_NULLABLE Nullability of the column in the table. 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.
SS_DATA_TYPE SQL Server data type, used by Open Data Services
extended stored procedures.
REFERENCES
Transact - SQL Reference Help; search on: "sp_addlinkedserver"; "sp_tables_ex"; "sp_linkedservers"; "sp_columns_ex"
APPLIES TO
| Article Translations
|

Back to the top
