March 24, 2010 at 9:38 am
Does any body know how we can get the actual owner (username) of the table using a query?
March 24, 2010 at 9:51 am
It sounds like you are thinking every table has an owner the way Oracle works; since SQL 2005, that's not true any more.
now everything is part of a schema, and people have rights to the schema.
some people might have db_owner rights to the schema, but that just means they can do anything to the objects, not that they truely "own" the objects.
you can find who has access to the objects, but there's no true "owner"
Lowell
March 24, 2010 at 9:56 am
OK. Thanks for your explanation. I am in the process of deleting unwanted tables that were created by me so I was trying to find a way to get only those tables.
March 24, 2010 at 10:03 am
select o.name as owner from sysobjects o with (nolock) inner join sysusers u with (nolock) on o.uid = u.uid
where u.name = 'username'
Hope this helps.
Mark
March 24, 2010 at 10:07 am
m_p_weber (3/24/2010)
select o.name as owner from sysobjects o with (nolock) inner join sysusers u with (nolock) on o.uid = u.uidwhere u.name = 'username'
Those are both deprecated system objects included only for backward compatability with SQL 2000. They should not be used in new development, partially because they don't show 'new' features like schemas.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 24, 2010 at 10:12 am
The o.name displays the object name.
But even if I choose u.name, it displays the generic owner name like "dbo" or "sys", it does not display the actual owner name like "siva" or something like that
March 24, 2010 at 10:15 am
Thanks for your answer. I got almost the same answer from Lowell that it is not possible
March 24, 2010 at 10:36 am
To find out the schema_owner for each table, you could do the following:
Select o.name, schema_name(o.schema_id)
From sys.objects o
To find out further permissions, I have a blog post on the topic at:
http://jasonbrimhall.info/?p=391
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 24, 2010 at 10:40 am
Thanks. This query also returns "dbo", not the NT login or the database userid of the user
March 24, 2010 at 10:43 am
srivishiva (3/24/2010)
Thanks. This query also returns "dbo", not the NT login or the database userid of the user
You will note that I specified that it will return the schema owner. Since a schema owns the table and not a user. This script is a more preferred script for 2005 due to object deprecation.
To find what users have what permissions to which objects, check the link.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 24, 2010 at 10:46 am
OK. Thanks again
March 24, 2010 at 10:48 am
You're welcome.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply