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:
> Select * from INFORMATION_SCHEMA.TABLES
> Select * from INFORMATION_SCHEMA.VIEWS
> --
> David G.
|||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?
>
>
|||Dan Guzman wrote:[vbcol=seagreen]
> 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...
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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment