Returns a list of objects that can be queried in the current environment (any object that can appear in a FROM clause).
sp_tables [[@name =] 'name']
[,[@owner =] 'owner']
[,[@qualifier =] 'qualifier']
[,[@type =] "type"]
In Microsoft® SQL Server™, if the current user owns a table with the specified name, the columns of that table are returned. If the owner is not specified and the current user does not own a table with the specified name, this procedure looks for a table with the specified name owned by the database owner. If one exists, the columns of that table are returned.
Note Single quotation marks must surround each table type, and double quotation marks must enclose the entire parameter. Table types must be uppercase. If SET QUOTED_IDENTIFIER is ON, each single quotation mark must be doubled and the entire parameter must be surrounded by single quotation marks.
None
Column name | Data type | Description |
---|---|---|
TABLE_QUALIFIER | sysname | Table qualifier name. In SQL Server, this column represents the database name. This field can be NULL. |
TABLE_OWNER | sysname | Table 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_NAME | sysname | Table name. This field always returns a value. |
TABLE_TYPE | varchar(32) | Table, system table, or view. |
REMARKS | varchar(254) | SQL Server does not return a value for this column. |
For maximum interoperability, the gateway client should assume only SQL-92-standard SQL pattern matching (the % and _ wildcards).
Privilege information about the current user’s read or write access to a specific table is not always checked, so access is not guaranteed. This result set includes not only tables and views, but also synonyms and aliases for gateways to DBMS products that support those types. If the server attribute ACCESSIBLE_TABLES is Y in the result set for sp_server_info, only tables that are accessible by the current user are returned.
sp_tables is equivalent to SQLTables in ODBC. The results returned are ordered by TABLE_TYPE, TABLE_QUALIFIER, TABLE_OWNER, and TABLE_NAME.
Execute permission default to public role.
EXEC sp_tables
EXEC sp_tables syscolumns, dbo, Company, "'SYSTEM TABLE'"