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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…