Saturday, February 25, 2012

retrieve list of tables

How can I get a list of table names or SPs in my database?
Not having much luck with BOL.
thanksHi
They are stored in sysobjects. BOL has info on that.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"shank" <shank@.tampabay.rr.com> wrote in message
news:uCjpNQCLFHA.3332@.TK2MSFTNGP15.phx.gbl...
> How can I get a list of table names or SPs in my database?
> Not having much luck with BOL.
> thanks
>|||Query system views information_schema.'
Example:
use northwind
go
select
*
from
information_schema.tables
where
table_type = 'base table'
select
*
from
information_schema.routines
where
routine_type = 'procedure'
go
AMB
"shank" wrote:

> How can I get a list of table names or SPs in my database?
> Not having much luck with BOL.
> thanks
>
>|||Go to the index tab in Books Online and type in "INFORMATION_SCHEMA". That
should get you a great start.
You can find information on how to view them by typing this in: "meta data,
obtaining with information schema views"
"shank" <shank@.tampabay.rr.com> wrote in message
news:uCjpNQCLFHA.3332@.TK2MSFTNGP15.phx.gbl...
> How can I get a list of table names or SPs in my database?
> Not having much luck with BOL.
> thanks
>|||SELECT Objects.name FROM dbo.sysobjects Objects
WHERE ((OBJECTPROPERTY(id, 'IsView') = 1) OR (OBJECTPROPERTY(id,
'IsProcedure') = 1) OR (OBJECTPROPERTY(id, 'IsUserTable') = 1))
This will give you the list of all tables, views and stored procedures of
your database.
Thank you
Baiju
"shank" <shank@.tampabay.rr.com> wrote in message
news:uCjpNQCLFHA.3332@.TK2MSFTNGP15.phx.gbl...
> How can I get a list of table names or SPs in my database?
> Not having much luck with BOL.
> thanks
>|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
Use the SQL Standard views in the INFORMATION_SCHEMA.
Tables (and Views in some systems):
SELECT TABLE_TYPE, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME NOT LIKE 'sys%' -- avoid system views
ORDER BY TABLE_TYPE, TABLE_NAME
--Views:
SELECT TABLE_NAME as view_name
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME NOT LIKE 'sys%' -- avoid system views
ORDER BY TABLE_NAME
--Stored Procedures:
SELECT ROUTINE_TYPE, ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES
WHERE SPECIFIC_SCHEMA = 'dbo'
AND ROUTINE_NAME NOT LIKE 'dt_%' -- avoid system routines
ORDER BY ROUTINE_TYPE, ROUTINE_NAME
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/ AwUBQjzMAYechKqOuFEgEQIEBwCfaOyb9ABeCNUL
hWCStiSNslhLlc4AoNAB
bbFnxkmvwTs6FwJ73wVNPqRV
=+MLw
--END PGP SIGNATURE--
Baiju wrote:
> SELECT Objects.name FROM dbo.sysobjects Objects
> WHERE ((OBJECTPROPERTY(id, 'IsView') = 1) OR (OBJECTPROPERTY(id,
> 'IsProcedure') = 1) OR (OBJECTPROPERTY(id, 'IsUserTable') = 1))
> This will give you the list of all tables, views and stored procedures of
> your database.
> Thank you
> Baiju
> "shank" <shank@.tampabay.rr.com> wrote in message
> news:uCjpNQCLFHA.3332@.TK2MSFTNGP15.phx.gbl...
>

No comments:

Post a Comment