I needed to get a unique database ID for product licensing reasons and eventually went with service_broker_guid
. Eg
SELECT db.service_broker_guid FROM sys.databases db WHERE db.name = 'MyDatabase';
Result: ED2E8477-CDC3-49DF-ABEE-341B3E9277DF
NOTE: This value is usually 00000000-0000-0000-0000-000000000000
for databases where is_broker_enabled = 0
. In our case, though, we just hunted for the first value that wasn't zeros:
SELECT TOP(1) service_broker_guid FROM sys.databases WHERE service_broker_guid <> '00000000-0000-0000-0000-000000000000' ORDER BY database_id;
I think you're fairly safe with that unless the database is moved or recreated but I haven't exhaustively tested that. (We'd just issue a new license key in the event of a customer issue.)