Description:
Returns a list of objects that can appear in the clause FROM (table, view).
Syntax:
sp_tables
[[
@table_name =] 'name']
[, [
@table_owner =] 'owner'
[, [
@table_qualifier =] 'qualifier']
[, [
@table_type =] "'type'"]
@table_name |
Name of the returned object with the default value of NULL. So called wild-chars '%' and '_' can be used in the text. |
@table_owner |
Owner of the returned object with the default value of NULL. with the default value of NULL. So called wild-chars '%' and '_' can be used in the text. |
@table_qualifier |
Database of the returned object |
@table_type |
Type of returned objects ('TABLE', 'SYSTEM TABLE', 'VIEW') with the default value of NULL. It goes about a list of types (separated by comma) where each type is enclosed in single quotation marks (') and the whole list in double quotation marks ("). |
Example1:
Displays all non-system tables ('TABLE') in the current database.
EXEC sp_tables @table_type="'TABLE'"
Example2:
Displays all non-system tables, beginning with specified characters 'da', in the current database (the same by several ways)
EXEC sp_tables @table_name='da%',@table_type="'TABLE'"
EXEC sp_tables 'da%',@table_type="'TABLE'"
EXEC sp_tables 'da%', null, null, "'TABLE'"
EXEC sp_tables 'da%', 'dbo', 'pm_data', "'TABLE'"