SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Find all objects in Server Owned by a Login

By RBarry Young, 2008/08/28

Total article views: 1401 | Views in the last 30 days: 60

In response to a request for a script to show all of the objects on a server onwed by a Login. I didn't know of any tool built-in to do this, so I wrote the following proc (SQL Server 2005 only).

Note the following featues also:

  1. No cursors or other Loops (but total number of databases is limitedt to 255).
  2. If the DB User for a Login is the explicit Owner for an object, then that will be reported.
  3. If there is no explicit owner for an object, then the Login of the DB User that owns the schema containing the object will be returned as the owner.
  4. If there is no explicit owner for an object and the object is contained in the [dbo] schema, then the Login that owns the database will be returned as the object's owner (this is the correct method of assesing object ownership in SQL server 2005).

If the Dynamic SQL concerns you, then notice that the Login name filter is only applied at the end. This means that you could also take the PRINT output and turn it into a static View. If you leave off the Login name WHERE clause, then this view returns every SQL object in your server with it's proper owner. This static View cna be preserved and reused as-is so long as your database configuration does not change.

You could write a SQL Server 2000 version of this also, but it would be significantly different, because of the large changes in the Schema/Owner security model, though probably simpler.

 

By RBarry Young, 2008/08/28

Total article views: 1401 | Views in the last 30 days: 60
Your response
 
 
Related tags
 
 
Contribute
Like this? Try these...

udf_is_database_available

(not yet rated) | 596 reads

Free registration required...

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Login (existing users)

Login

Email:   Password:   Remember me: Forgotten your password?

Register (new users)

Register

Email:   Password:
Confirm:

Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

Steve Jones
Editor, SQLServerCentral.com