SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to change object owner......


How to change object owner......

Author
Message
JMSM
JMSM
Mr or Mrs. 500
Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)

Group: General Forum Members
Points: 520 Visits: 977
Hello,

We've got a lot of objects in one database that are owned by another user then dbo.
I need to know all objects that this owner owns, if i can change them to dbo without any impact in the environment and how can i change all of them to be owned by dbo.

I've tried to replicate this environment in a test instance and i use the following query to get the following information, the point is that i can't change the schema/owner of this table and pk to dbo

select a.name, a.xtype, a.type, c.name as 'Schema Name'
from sysobjects a, sysusers b, sys.schemas c
where a.name like '%TblOwner%' and b.uid = c.principal_id and c.name like '%Tbl%'
go

Object Name Xtype Type Schema Name
TblOwnerName U U tblownerexample
pk_TblOwnerName PK K tblownerexample

Can you send me the sintax to get all this information?

Thanks and regards,
JMSM Wink
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19354 Visits: 14900
Can you clarify what version of SQL Server you are using? You have posted in a SQL Server 2000 forum, but have used the sys.schemas system view which does not exist in SQL Server 2000.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
JMSM
JMSM
Mr or Mrs. 500
Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)Mr or Mrs. 500 (520 reputation)

Group: General Forum Members
Points: 520 Visits: 977
Hi,

I'm using SQL Server 2005.
Sorry.

Thanks and regards
JMSM Wink
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19354 Visits: 14900
IN SQL Server 2005, typically, objects are not owned by users anymore they are owned by schemas, although a user CAN still own an object, you have to do some work to do it though.

I think the query you want to run is:


SELECT
c.[name] AS schema_name,
T.[name] AS table_name,
T.[object_id],
T.principal_id,
T.[schema_id],
T.[type],
T.type_desc,
T.create_date,
T.modify_date
FROM
sys.tables AS T JOIN
sys.schemas AS c
ON T.[schema_id] = C.[schema_id]



If the principal_id is not null then the object is owned by a user not a schema. Here's a blog post about this: http://www.sqlservercentral.com/blogs/brian_kelley/archive/2009/03/04/owning-an-object-in-sql-server-2005-2008.aspx

If you need to change an objects schema, and I don't think this is intuitive at all, you need to use the ALTER SCHEMA command like this (uses AdventureWorks):

ALTER SCHEMA Production TRANSFER Purchasing.ProductVendor





Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
amarnath_sk
amarnath_sk
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 220
http://www.developmentnow.com/g/109_2006_5_0_0_758716/change-object-owner-with-a-wildcard.htm
J-440512
J-440512
Right there with Babe
Right there with Babe (769 reputation)Right there with Babe (769 reputation)Right there with Babe (769 reputation)Right there with Babe (769 reputation)Right there with Babe (769 reputation)Right there with Babe (769 reputation)Right there with Babe (769 reputation)Right there with Babe (769 reputation)

Group: General Forum Members
Points: 769 Visits: 949
Why is an SS2K5 question posted in this SS2K forum ?

If users keep mixing forum contents, pretty soon it will become that much more difficult to find something in the mass of information.
Steve Jones
Steve Jones
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: Administrators
Points: 65653 Visits: 19118
Moving to 2005

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Perry Whittle
Perry Whittle
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20831 Visits: 17245
the following should generate the alter schema commands to change schema for any Stored Proc not owned by dbo


select 'alter schema dbo transfer ' + sch.name + '.' + tab.name
from sys.schemas sch inner join sys.objects tab on sch.schema_id = tab.schema_id
where sch.name <> 'dbo' and tab.type = 'P'
order by tab.name



-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search