Obtaining a unique database identifier for SQL Server 2005 and later

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

    Whatever means SMO uses to get the database guid, you should be able to do the same. If you have problems figuring out what is SMO doing, you can use profiler to monitor what t executes and figure it out.

    In this case probably SMO reads the database_guid value from sys.database_recovery_status:

    Used to relate all the database files of a database together. All files must have this GUID in their header page for the database to start as expected. Only one database should ever have this GUID, but duplicates can be created by copying and attaching databases. RESTORE always generates a new GUID when you restore a database that does not yet exist.

提交回复
热议问题