Obtaining a unique database identifier for SQL Server 2005 and later

前端 未结 4 797
清酒与你
清酒与你 2021-01-20 12:14

Is there a way to obtain a unique database identifier (such as a GUID) from a SQL 2005 database?

I found this article: http://msdn.microsoft.com/en-us/library/micr

4条回答
  •  温柔的废话
    2021-01-20 12:31

    I don't know which GUID SMO returns, but you could use

    select service_broker_guid from sys.databases
    

    which is != Guid.Empty for all databases except master and model.

    I found that not all databases have a NOT NULL sys.database_recovery_status.database_guid, as was suggested by Remus.

    Tests done on SQL2008

提交回复
热议问题