Owned Schema

  • Is there a query to find out if a sql user or role owns a schema ?

    I know hows to find the default schema, when I try to drop a sql user or role it says that the 'user or role owns a schema'

    Which dmv or sys table can I query for this ?

  • This should help:

    SELECT sc.name AS schema_name,

    dbp.name AS owning_database_principal_name,

    srp.name AS owning_server_principal_name

    FROM sys.schemas AS sc

    INNER JOIN sys.database_principals AS dbp

    ON sc.principal_id = dbp.principal_id

    INNER JOIN sys.server_principals AS srp

    ON srp.sid = dbp.sid

    -- Gianluca Sartori

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply