Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 change object owner batchly

Author  Topic 

p2bl
Yak Posting Veteran

54 Posts

Posted - 2002-06-30 : 05:12:49
How can I change object owner batchly,have I seach 'sysobjects'tables
and use sp_changeobejctowner one by one?

========================
look!

Nazim
A custom title

1408 Posts

Posted - 2002-06-30 : 09:20:41
Read this Article http://www.sqlteam.com/item.asp?ItemID=1283 .

-------------------------
What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson
Go to Top of Page

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-06-30 : 09:35:01
The following example generates the required scripts for you. It's taken from my one of my articles at: http://vyaskn.tripod.com/generate_scripts_repetitive_sql_tasks.htm

SELECT 'EXEC sp_changeobjectowner ''' + TABLE_SCHEMA + '.' + TABLE_NAME + ''', dbo'
FROM INFORMATION_SCHEMA.TABLES
WHERE
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
AND TABLE_TYPE = 'BASE TABLE' /*Check the TABLE_TYPE against 'VIEW' to work with views*/
--AND TABLE_SCHEMA = 'Admin1' /*To change the owner of tables owned by 'Admin1' only*/
--AND TABLE_NAME LIKE 'Tbl%' /*To change the owner of tables starting with a particular pattern*/
GO

You just need to copy the output of above command, verify it, and just run it.

If you want to automate it completely, then you can use the above code to create a cursor.

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page
   

- Advertisement -