Is there a query I can write that joins 2 system tables to return the owners of objects (e.g. tables) and the object's name?
Thanks,
Dave
IN SQL SERVER 200 the SCHEMA IN the information_VIEW represents the owner OF an objects e.g. FOR tables
SELECT TABLE_SCHEMA FROM [INFORMATION_SCHEMA].TABLES
IN SQL SERVER 2005, you will have TO determine the owner OF the SCHEMA instead using
SELECT Name FROM sys.Schemas
INNER JOIN sys.server_principals
ON [Schemas].principal_id = [server_principals].Principal_id
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||In SQL SERVER 2005, because of the ALTER AUTHORIZATION clause, the schema owner may not always be the object owner
See, http://msdn2.microsoft.com/en-us/library/ms187359.aspx
So, an alternative to the above query for SQL SERVER 2005 is
select user_name(objectproperty(object_id,'OwnerId')), name from sys.objects
This always returns the correct owner of the object and takes 'ALTER AUTHORIZATION' into account.
No comments:
Post a Comment