Database List

  • Goal: to get list of all databases except system databases

    the way i am doing is

    SELECT [name]

    FROM sys.databases

    This query returns all databases including system databases.

    Is there any way to get database list instead of using underlying query

    SELECT [name] FROM sys.databases

    where name not in ('master', 'tempdb', 'model', 'msdb')

  • How about this?

    select * from sys.databases where database_id > 4

  • select * from sys.databases where database_id > 4

    do these four system databases would always fall under database id 1-4? if so, then i can consider this query too. By mentioning system database names, i am sure that i'll not get back names of these databases in any case.

  • Yes. Either one works fine up to version SQL2008. Unless system databases have changes after SQL2008.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply