Wednesday, March 7, 2012

How to retrieve tables' name?

Hi,
I want to retrive all tables and views name from a database.
How can I do this?GoodMorningSky wrote:
> Hi,
> I want to retrive all tables and views name from a database.
> How can I do this?
Select * from INFORMATION_SCHEMA.TABLES
Select * from INFORMATION_SCHEMA.VIEWS
--
David G.|||INFORMATION_SCHEMA.TABLES returns both tables and views so only this view
needs to be accessed to return a list of both.
--tables and views
SELECT * FROM INFORMATION_SCHEMA.TABLES
--tables only
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
--views only
SELECT * FROM INFORMATION_SCHEMA.VIEWS
or
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'VIEW'
--
Hope this helps.
Dan Guzman
SQL Server MVP
"David G." <david_nospam@.nospam.com> wrote in message
news:OEJXuJ5mEHA.596@.TK2MSFTNGP11.phx.gbl...
> GoodMorningSky wrote:
>> Hi,
>> I want to retrive all tables and views name from a database.
>> How can I do this?
> Select * from INFORMATION_SCHEMA.TABLES
> Select * from INFORMATION_SCHEMA.VIEWS
> --
> David G.|||Dan Guzman wrote:
> INFORMATION_SCHEMA.TABLES returns both tables and views so only this
> view needs to be accessed to return a list of both.
> --tables and views
> SELECT * FROM INFORMATION_SCHEMA.TABLES
> --tables only
> SELECT * FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> --views only
> SELECT * FROM INFORMATION_SCHEMA.VIEWS
> or
> SELECT * FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'VIEW'
>
> "David G." <david_nospam@.nospam.com> wrote in message
> news:OEJXuJ5mEHA.596@.TK2MSFTNGP11.phx.gbl...
>> GoodMorningSky wrote:
>> Hi,
>> I want to retrive all tables and views name from a database.
>> How can I do this?
>> Select * from INFORMATION_SCHEMA.TABLES
>> Select * from INFORMATION_SCHEMA.VIEWS
>> --
>> David G.
Never even looked at the output... silly me. I'm so used to hitting the
system tables directly... Thanks for the clarification.
--
David Gugick
Imceda Software
www.imceda.com|||Select * from INFORMATION_SCHEMA.TABLES
Select * from INFORMATION_SCHEMA.VIEWS
"GoodMorningSky" wrote:
> Hi,
> I want to retrive all tables and views name from a database.
> How can I do this?
>
>

No comments:

Post a Comment