Azure SQL Database: Validating logical_database_guid as a stable identifier for least-privilege access — Permissions and best practices

Ramu-1383 0 Reputation points
2026-10-09T22:18:33.7166667+00:00

Problem description

I am seeking confirmation on whether using logical_database_guid as a database-local, stable identifier is supported and recommended for least-privilege access when connecting directly to a standalone Azure SQL Database in a General Purpose serverless deployment.

Environment

Azure SQL Database, standalone single database, General Purpose serverless, in a region not specified in the case.

What I've already tried

Based on the case details, I designed a collector to connect at the database level with either a contained SQL user or a contained Microsoft Entra service principal user. I considered using logical_database_guid from sys.dm_user_db_resource_governance as the in-database identifier for the database. I shared a partial query that selects database_name, database_id, and logical_database_guid. No specific error messages or permission changes are documented, and the outcome of the query under each authentication method is not recorded.

Current status

I am requesting confirmation that logical_database_guid is a supported, durable, and appropriate identifier for this use case, and whether the pattern of granting minimal permissions (such as VIEW DATABASE STATE or wrapping in a stored procedure with EXECUTE AS OWNER) aligns with best practices for achieving least-privilege access in Azure SQL Database.

Azure SQL Database
0 comments No comments

1 answer

Sort by: Most helpful
  1. Allan Solomon Mejia 10,385 Reputation points
    2026-10-09T23:05:14.68+00:00

    Hello @Ramu-1383

    Yes, logical_database_guid is the appropriate database-local identifier for this scenario. It is a unique identifier that remains unchanged throughout the lifetime of the user database. Renaming the database or changing its service-level objective doesn’t change the value.

    Use sys.dm_user_db_resource_governance, not sys.database_service_objectives:

    SELECT logical_database_guid
    FROM sys.dm_user_db_resource_governance
    WHERE database_id = DB_ID();
    

    For a standalone General Purpose Azure SQL Database, VIEW DATABASE STATE is the required database-level permission:

    GRANT VIEW DATABASE STATE TO [collector_user];
    

    This works for either a contained SQL user or contained Microsoft Entra principal, provided the permission is granted in the target database. sys.dm_user_db_resource_governance permissions.

    If granting VIEW DATABASE STATE directly exposes more database-state information than the collector requires, use a stored procedure executed under a dedicated, non-login database user:

    CREATE USER [DbGuidReader] WITHOUT LOGIN;
    GRANT VIEW DATABASE STATE TO [DbGuidReader];
    GO
    CREATE OR ALTER PROCEDURE dbo.GetLogicalDatabaseGuid
    WITH EXECUTE AS 'DbGuidReader'
    AS
    BEGIN
        SET NOCOUNT ON;
        SELECT logical_database_guid
        FROM sys.dm_user_db_resource_governance
        WHERE database_id = DB_ID();
    END;
    GO
    GRANT EXECUTE ON OBJECT::dbo.GetLogicalDatabaseGuid
    TO [collector_user];
    

    A user created with WITHOUT LOGIN can hold permissions and be used as an execution context. EXECUTE AS allows callers to receive permission only on the module while referenced-object permissions are evaluated against the designated execution principal.

    I recommend the dedicated DbGuidReader principal instead of EXECUTE AS OWNER. Use the least-privileged execution principal and not the database owner unless owner-level permissions are required.

    References:

    sys.dm_user_db_resource_governance (Transact-SQL)

    EXECUTE AS clause (Transact-SQL)

    CREATE USER (Transact-SQL)

    GRANT database permissions (Transact-SQL)

    Microsoft Entra service principals with Azure SQL


    Help make this community better for everyone: If this answer helped or resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution. Thank you.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.