I built a powershell script for collecting database information with the help of the class "Microsoft.SqlServer.Management.Smo.Server". My script run into an error because one database has no DatabaseGuid. How could that happen? I thought every database has a database guid?! This database is in state "offline". I set an other database to state "offline" but the database has still a guid.

I thought each database reaceives a persistent guid, or?!


  • 1
    From what table(s) are you trying to retrieve a DatabaseGuid? Please post your script(s). Also, update your question (or tags) to identify the version of SQL Server you're using. (2016, etc.) Commented Jan 8, 2018 at 10:04

1 Answer 1


From this post: Obtaining a unique database identifier for SQL Server 2005 and later it seems that

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.

And if you open the documentation sys.database_recovery_status (Transact-SQL) you'll find that

NULL= Database is offline, or the database will not start.

I tried to put some my databases offline and to query database_guid from sys.database_recovery_status and it is NULL while it's not NULL when bring these databases online again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.