How to determine if the database is a master, model, msdb using DMO or programatically

  • How to determine if the database is a master, model, msdb using DMO or programatically using some property or status and not by comparing the names.

  • Look for database_id

    --Ramesh


  • Does the database_id remains same for any version of sql like 2000, 2005, 2007. Is this the best way or is there any propery which says that this is master, model or msdb.?

    master1

    tempdb2

    model3

    msdb4

    Kiran

  • I could be wrong but I belive that is the case. Every server I've looked at (more than 20 over 2000 and 2005) has those values for the system DBs.

    Kenneth Fisher

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]

  • Yes the dbid remains same for all version

  • EXCEPT for distribution 😉


    * Noel

  • Try this ..

    Select * from sysdatabases .

    The Compatibility level cmptlevel is different for 2000(80) and 2005 (90) sysdatadases.

    🙂

    "More Green More Oxygen !! Plant a tree today"

  • Hi,

    You can use the following query :

    USE Master

    select * from sysdatabases

    to identify the current set of databases exiting on your sql server..

    Rgds

    Avaneesh.

    "The severity of itch is inversely proportional to the ability to reach it" :))

  • u can try database_id

Viewing 9 posts - 1 through 8 (of 8 total)

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