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 ownership of table

Author  Topic 

vwilsonjr
Starting Member

45 Posts

Posted - 2002-12-31 : 14:08:15
I have a Intranet program that created about 50 tables using an account as the owner. I want to change the owner and delete the exesting user being used. I can't delete if because it owns objects. How do I change the ownership?

tool
Starting Member

26 Posts

Posted - 2002-12-31 : 14:18:11
Try looking up sp_changeobjectowner in Books Online.

Go to Top of Page

vwilsonjr
Starting Member

45 Posts

Posted - 2002-12-31 : 17:35:58
Is there any sp that will do all tables (objects) that is associated with a user? I tried the sp_changeobjectowner, but I really don't want to spend my evening going table by table.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2002-12-31 : 17:58:14
This should work for you:

SELECT 'EXEC sp_changeobjectowner ' + name + ', ''dbo''' + '
GO'
FROM sysobjects
WHERE type = 'U'
AND name <> 'dtproperties'
ORDER BY name
GO

Just run the above code (change dbo to whatever user you want to own the objects), copy the output into a new window and then execute the output.


If you want to do more than just tables, then modify the above code to include the other types (WHERE type = ...).


Edited by - tduggan on 12/31/2002 17:59:25
Go to Top of Page
   

- Advertisement -