Obtaining a unique database identifier for SQL Server 2005 and later

前端 未结 4 821
清酒与你
清酒与你 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:25

    For others who are looking for a query to return the GUID of a database:

    SELECT d.name, drs.database_guid, d.group_database_id 
    FROM sys.databases d 
    JOIN sys.database_recovery_status drs
    ON d.database_id = drs.database_id
    

    It returns the database name, database GUID and GUID of this database in availability group. If database is not in AG, the last value returns null. This works in SQL Server 2016.

提交回复
热议问题