SQL Server: How to tell if a database is a system database?

Just dived into Microsoft.SqlServer.Management.Smo.Database object (which is provided by Microsoft itself!)
They simply do this using following statement:

CAST(case when dtb.name in ('master','model','msdb','tempdb') 
   then 1 
   else dtb.is_distributor end AS bit) AS [IsSystemObject]

In short: if a database is named master, model, msdb or tempdb, it IS a system db;
it is also a system db, if field is_distributor = 1 in the view sys.databases.

Hope this helps

Jimmy

Leave a Comment