Wednesday, March 21, 2012

listing non system databases

I know sp_databases can list all the databases, but how can i only list
non-system databases? I just want to get a list of user databasesYou can query the INFORMATION_SCHEMA.SCHEMATA view or the sysdatabases
system table to the the list of all databases. You can avoid the master,
model, msdb, mssqlweb, tempdb, Pubs & Northwind databases in the WHERE
clause to get the list of non-system databases.
Anith|||Hi
If you profile SQL Management Studio in SQL 2005 to see how it determines a
system database, you will see that it queries sysdatabases and determines
that the are system database by their name.
John
"Brian Henry" <nospam@.nospam.com> wrote in message
news:u5cw%23c7CGHA.3064@.TK2MSFTNGP10.phx.gbl...
>I know sp_databases can list all the databases, but how can i only list
>non-system databases? I just want to get a list of user databases
>|||> You can query the INFORMATION_SCHEMA.SCHEMATA view
Note that this view has a different meaning in 2005, where it returns the sc
hemas in the current
database.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:u734707CGHA.2704@.TK2MSFTNGP15.phx.gbl...
> You can query the INFORMATION_SCHEMA.SCHEMATA view or the sysdatabases sys
tem table to the the
> list of all databases. You can avoid the master, model, msdb, mssqlweb, te
mpdb, Pubs & Northwind
> databases in the WHERE clause to get the list of non-system databases.
> --
> Anith
>|||Yes, thanks. In 2005, use sys.databases instead.
Anith

No comments:

Post a Comment