[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2643
  • Last Modified:

how to get sql server instance guid

From what I understand each sql server instance is assigned a unique guid. Whats the t-sql statement to get that guid?
  • 2
1 Solution
You could use the file_guid property for the first physical file in the database:

select top 1 [file_guid] from [sys].[database_files]

(although taking a physical backup would duplicate it)

To uniquely identify the instance, combine the full instance name (server and sql server) along with the above - again, it may nt be 101% unique, but "close enough for government work", as you Americans say! :)


glenn_rAuthor Commented:
When I query that value its 'NULL'. Any ideas why?

We're in Canada, 'North America' you could say. US is just a stones throw south 1 hour. "I reckon we aim fer 80% round deez parts!"
It's possible that your db file doesn't have a GUID
Try looking at
select   *  from [sys].[database_files]
and you should find files with GUIDs - it's a different pair for each DB.
BTW, the master and model databases don't have GUIDs for their files.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now