I want to get list of database names under a server,
and list of table names under a database.
How can I do this with query?Probably a better way of doing this through InformationSchema but...
SELECT Name from master.dbo.sysdatabases
In each database
SELECT Name from sysobjects WHERE Type = 'U'
HTH
Rick Sawtell
MCT, MCSD, MCDBA
"GoodMorningSky" <sky@.forever21.com> wrote in message
news:%23oKl4ZJrEHA.516@.TK2MSFTNGP09.phx.gbl...
> I want to get list of database names under a server,
> and list of table names under a database.
> How can I do this with query?
>|||-- All databases
SELECT name
FROM master..sysdatabases
-- All tables in a database
select name, *
FROM Northwind..sysobjects
where xtype = 'U'
Greetings, John
"GoodMorningSky" <sky@.forever21.com> wrote in message
news:%23oKl4ZJrEHA.516@.TK2MSFTNGP09.phx.gbl...
> I want to get list of database names under a server,
> and list of table names under a database.
> How can I do this with query?
>|||You can also use the ANSI-standard INFORMATION_SCHEMA views:
SELECT CATALOG_NAME
FROM INFORMATION_SCHEMA.SCHEMATA
SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND
OBJECTPROPERTY(OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)),
'IsMSShipped') = 0
--
Hope this helps.
Dan Guzman
SQL Server MVP
"GoodMorningSky" <sky@.forever21.com> wrote in message
news:%23oKl4ZJrEHA.516@.TK2MSFTNGP09.phx.gbl...
>I want to get list of database names under a server,
> and list of table names under a database.
> How can I do this with query?
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment