Sql-server – SQL Server Security Hierarchy

permissionsSecuritysql-server-2008

I have been working as a developer with SQL Server for years without asking the question, "what is dbo", a shame. Recently I have been studying the security model of SQL Server 2008. I have been overwhelmed by lots of concepts. Please clarify some concepts for me, and correct me where I am wrong. I don't need a thorough explanation on everything, just an idea what does what and the relationships involved:

LOGIN:  Server level (SQL Server login or Windows login).
USER:   Database level (a user is mapped to a login).
ROLE:   Users belong to a role. Can be at server level or at database level
        with permissions attached.
SCHEMA: Database objects belong to a schema (or dbo by default)
PERMISSION:
        For database objects or schema. A user or a role has permissions for
        an object or a schema.
OWNER:  Is it the user who created a object or schema? What does it do?
        How does it work? Where I can see the owner of a object in SSMS?
        I see only schema.object

Best Answer

An owner is a database principal that has ownership of a particular object, giving that principal full rights to the object(including ALTER, SELECT, INSERT, UPDATE, and DELETE). This principal can either be a database user or schema, depending on the context in which the object was created and the permissions of the principal that created the object. In the case of no explicit object ownership, the object is owned by the related schema owner.

There is also the db_owner role which exists in each database. Members of this role are considered to have ownership of the database and all objects within that database. Essentially, members of the db_owner role have "sysadmin/sa" rights in that specific database.

'dbo' is a default database user that is made a member of the db_owner role. Additionally, the 'dbo' schema is also created and used as default schema to create objects within. This schema is owned by the 'dbo' user.

To view object ownership, you can use the following query against the DMVs:

select
    SCHEMA_NAME(s.schema_id)+'.'+OBJECT_name(o.object_id) [ObjectName]
    ,u.name [ObjectOwner]
    ,so.name [SchemaOwner]
from
    sys.objects o
    left join sys.schemas s on (o.schema_id = s.schema_id)
    left join sys.database_principals so on (s.principal_id = so.principal_id)
    left join sys.database_principals u on (o.principal_id = u.principal_id)

For more detail, you can read Aaron's link or this article from Kathi Kellenberger.