SQL Server Performance

user databases

Discussion in 'SQL Server 2005 General Developer Questions' started by arkiboys, Jul 21, 2008.

  1. arkiboys Member

    I would like to find out if there is a user database inside a sql server machine.
    Looking at booksonline I have found, select * from sysdatabases.
    This seems to return all the databases including the system and the user created databases.
    The field sid seems to be the only field with the same value for all the system databases but not for the user databases.
    Question:
    I am using the field sid to distinguish between user and system databases. This does not seem to be the correct field to do this.
    Any thoughts please?
    Thanks
  2. FrankKalis Moderator

    System database do have a database_id <= 4.
    Alternatively you can filter out the system dbs by name like:
    SELECT ... FROM ... WHERE [name] NOT IN('master', 'model', 'tempdb', 'msdb')

Share This Page