Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to change object owner...... Expand / Collapse
Author
Message
Posted Friday, March 6, 2009 10:44 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 4:53 AM
Points: 186, Visits: 818
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 ;)

Post #670471
Posted Friday, March 6, 2009 10:50 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:26 AM
Points: 10,381, Visits: 13,436
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

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
Post #670478
Posted Friday, March 6, 2009 11:45 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 4:53 AM
Points: 186, Visits: 818
Hi,

I'm using SQL Server 2005.
Sorry.

Thanks and regards
JMSM ;)
Post #670536
Posted Friday, March 6, 2009 1:08 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:26 AM
Points: 10,381, Visits: 13,436
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

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
Post #670607
Posted Monday, March 9, 2009 4:11 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, January 30, 2013 1:41 AM
Points: 40, Visits: 220




http://www.developmentnow.com/g/109_2006_5_0_0_758716/change-object-owner-with-a-wildcard.htm
Post #671335
Posted Tuesday, March 10, 2009 11:25 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 8:51 AM
Points: 441, Visits: 935
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.
Post #672647
Posted Tuesday, March 10, 2009 11:30 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 5:38 PM
Points: 31,368, Visits: 15,834
Moving to 2005






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #672652
Posted Tuesday, March 10, 2009 12:09 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 11:55 AM
Points: 6,752, Visits: 14,397
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"
Post #672679
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse