title: Is it possible to query the system databases in SQL server without using the names?
body: <p>When doing a query over several databases in SQL server (2005+) I find it sometimes necesary to exclude the system database (master, model, tempdb, msdb and distribution)</p>
  
  <p>Is there any OTHER way to filter these besides </p>
  
  <pre><code>where name not in (''master', 'model', 'tempdb', 'msdb', 'distribution')
  </code></pre>
  
  <p>I've looked at sys.databases and master.dbo.sysdatabases (not the same!)</p>
  
  <p>[UPDATE] an example query which I use to look for databases that have logshipping enabled</p>
  
  <pre><code>select d.name, p.last_backup_date, s.secondary_server, s.secondary_database
  from sys.databases d
      left outer join msdb..log_shipping_primary_databases p on p.primary_database = d.name
      left outer join msdb..log_shipping_primary_secondaries s on s.primary_id = p.primary_id
  where name not in ('model','master','tempdb','distribution','msdb')
  order by d.name
  </code></pre>
  
  <p>[UPDATE] This seems to be the 'least bad' way, unless someone else has a better way?</p>
  
  <pre><code>SELECT * FROM 
  master.sys.databases AS dtb 
  WHERE (dtb.database_id &lt; 5 or dtb.is_distributor = 1)
  </code></pre>