30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8: Exploring your Database Schema<br />

Object permissions and owners<br />

There is a whole variety of things you will need information on, in addition to details<br />

of the database objects; lists of permissions on each object, and the type of permissions<br />

they represent, for example. Listing 8-15 provides a query that lists the database-level<br />

permissions for the users (or particular user, if the final condition that is currently<br />

commented out is used.)<br />

SELECT CASE WHEN class_desc = 'DATABASE' THEN DB_NAME()<br />

WHEN class_desc = 'SCHEMA' THEN SCHEMA_NAME(major_id)<br />

WHEN class_desc = 'OBJECT_OR_COLUMN' THEN OBJECT_NAME(major_id)<br />

WHEN class_desc = 'DATABASE_PRINCIPAL' THEN USER_NAME(major_id)<br />

WHEN class_desc = 'TYPE' THEN TYPE_NAME(major_id)<br />

ELSE 'Huh??'<br />

END ,<br />

USER_NAME(grantee_principal_id) AS grantee ,<br />

USER_NAME(grantor_principal_id) AS grantor ,<br />

type ,<br />

Permission_Name ,<br />

State_Desc<br />

FROM sys.database_permissions<br />

WHERE Class_Desc IN ( 'DATABASE', 'SCHEMA', 'OBJECT_OR_COLUMN',<br />

'DATABASE_PRINCIPAL', 'TYPE' )<br />

- – and grantee_principal_id = DATABASE_PRINCIPAL_ID('public');<br />

Listing 8-15: Finding database-level permissions for each user.<br />

A different task is to explore the ownership of the various objects in your database, a task<br />

that Listing 8-16 makes a lot simpler.<br />

244

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!