Sorry a minor single quote mistake
EXEC sp_changeobjectowner 'Tablename', 'dbo'
Main Topics
Browse All TopicsWe have 2 databases. A live database that we copy every so often and restore into a test database. Every time we restore the database onto the test database (on a different server) a couple hundred tables have the db owner changed. Is there a script that can be run to change the db owner on just these tables all at once? The table names are all different but the first three letters of all of the tables that need to be changed are the same.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I'm not clear about what you want to do. The db_owner role owns everything within a database. You sound as if you have owners on your table?
Do you mean that you need to change the schema?
From BOL
ALTER SCHEMA schema_name TRANSFER securable_name
USE AdventureWorks;
GO
ALTER SCHEMA HumanResources TRANSFER Person.Address;
GO
You cannot use a wildcard, you would have to list each table change.
You could create a cursor
SELECT table_name
FROM INFORMATION_SCHEMA.tables
WHERE table_type = 'Base Table'
and table_schema = 'schema to be changed'
INTO @tb
Then for each table to be transferred
ALTER SCHEMA new_schema_name TRANSFER table;
Do one thing, use the query below
select 'Exec sp_changeobjectowner ''' + name + ''', ''dbo''' from sysobjects where xtype = 'U'
and copy all the results and execute them in a query analyser and it will change the tables owner, some which ar already having dbo as owner will give error but that doesnt affect anything.
Business Accounts
Answer for Membership
by: asvforcePosted on 2007-12-21 at 07:45:15ID: 20514268
EXEC sp_changeobjectowner 'Tablename, 'dbo'