How to determine the database when moving it to another server / instance

I am writing a tool that is used to perform several database operations.
But the tool should only be used with one specific database.

Now I'm looking for a way to safely identify the database to which the tool is connected.

At first, I thought about just checking the type string SERVERNAME\INSTANCE#Database.
I also found this question where the solution should use a GUID, but this GUID changes if the database is restored on another server.

The database should be recognized even if it is being moved to another server or instance or the database name is being changed.

Is there a reliable way to achieve this?

+4
source share
1 answer

You may be able to achieve this with an advanced property .

To create:

exec sp_addextendedproperty @name = 'dbUniqueIdentifier' @value = 'ABCD1234'

To confirm:

select value from sys.extended_properties where name = 'dbUniqueIdentifier'

In my organization, we use advanced properties to determine which assemblies and changes use the database schema. Properties are saved during backup / restore / migration.

+1
source

Source: https://habr.com/ru/post/1683944/


All Articles