TechNet
Export (0) Print
Expand All

sp_tables_ex (Transact-SQL)

 

Returns table information about the tables from the specified linked server.

Applies to: SQL Server (SQL Server 2008 through current version).

Topic link icon Transact-SQL Syntax Conventions

  
sp_tables_ex [ @table_server = ] 'table_server'   
     [ , [ @table_name = ] 'table_name' ]   
     [ , [ @table_schema = ] 'table_schema' ]  
     [ , [ @table_catalog = ] 'table_catalog' ]   
     [ , [ @table_type = ] 'table_type' ]   
     [ , [@fUsePattern = ] 'fUsePattern' ]  

[ @table_server= ] 'table_server'
Is the name of the linked server for which to return table information. table_server is sysname, with no default.

[ , [ @table_name= ] 'table_name']
Is the name of the table for which to return data type information. table_nameis sysname, with a default of NULL.

[ @table_schema= ] 'table_schema']
Is the table schema. table_schemais sysname, with a default of NULL.

[ @table_catalog= ] 'table_catalog'
Is the name of the database in which the specified table_name resides. table_catalog is sysname, with a default of NULL.

[ @table_type= ] 'table_type'
Is the type of the table to return. table_type is sysname, with a default of NULL, and can have one of the following values.

ValueDescription
ALIASName of an alias.
GLOBAL TEMPORARYName of a temporary table available system wide.
LOCAL TEMPORARYName of a temporary table available only to the current job.
SYNONYMName of a synonym.
SYSTEM TABLEName of a system table.
SYSTEM VIEWName of a system view.
TABLEName of a user table.
VIEWName of a view.

[ @fUsePattern= ] 'fUsePattern'
Determines whether the characters _, %, [, and ] are interpreted as wildcard characters. Valid values are 0 (pattern matching is off) and 1 (pattern matching is on). fUsePattern is bit, with a default of 1.

None

Column nameData typeDescription
TABLE_CATsysnameTable 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 other products, it represents the server name of the database environment of the table. This field can be NULL.
TABLE_SCHEMsysnameTable owner name. In SQL Server, this column represents the name of the database user who created the table. This field always returns a value.
TABLE_NAMEsysnameTable name. This field always returns a value.
TABLE_TYPEvarchar(32)Table, system table, or view.
REMARKSvarchar(254)SQL Server does not return a value for this column.

sp_tables_ex is executed by querying the TABLES 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_tables_ex returns an empty result set if the OLE DB provider of the specified linked server does not support the TABLES rowset of the IDBSchemaRowset interface.

Requires SELECT permission on the schema.

The following example returns information about the tables that are contained in the HumanResources schema in the AdventureWorks2012 database on the LONDON2 linked server.

EXEC sp_tables_ex @table_server = 'LONDON2',   
@table_catalog = 'AdventureWorks2012',   
@table_schema = 'HumanResources',   
@table_type = 'TABLE';  

Distributed Queries Stored Procedures (Transact-SQL)
sp_catalogs (Transact-SQL)
sp_columns_ex (Transact-SQL)
sp_column_privileges (Transact-SQL)
sp_foreignkeys (Transact-SQL)
sp_indexes (Transact-SQL)
sp_linkedservers (Transact-SQL)
sp_table_privileges (Transact-SQL)
System Stored Procedures (Transact-SQL)

Community Additions

ADD
Show:
© 2016 Microsoft