I changed the table schema from dbo to db_owner using the SQL statement below (SQL 2008 R2):
DECLARE @old sysname, @new sysname, @sql varchar(1000)
SELECT
@old = 'db_owner'
, @new = 'dbo'
, @sql = '
IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES
WHERE
QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?''
AND TABLE_SCHEMA = ''' + @old + '''
)
EXECUTE sp_changeobjectowner ''?'', ''' + @new + ''''
EXECUTE sp_MSforeachtable @sql
I need to change it back by switch the old and new name parameters, but I am getting an error:
Msg 15001, Level 16, State 1, Procedure sp_changeobjectowner, Line 75
Object ‘[db_owner].[language_link]’ does not exist or is not a valid
object for this operation.
That table does exist though and even with that old db_owner. Any way to fix this?
Here is a screenshot on how I could tell it is still owned by db_owner. Only some tables were moved back properly:

Are you sure you should be using sp_changeobjectowner? (Objects don’t really have owners anymore as of SQL 2005.) How did you verify that db_owner.language_link exists? Personally I would use
ALTER SCHEMAfor this and I would also lean toward catalog views (sys.tables) rather than information_schema.tables. Finally, I wouldn’t use the undocumented and unsupported sp_MSforeachtable – I have highlighted issues with sp_MSforeachdb that are likely potential issues here because the code is quite similar.EDIT adding code to find objects that are common to both schemas. And to move the ones already in the new schema to some dummy schema:
But really it just sounds like you messed something up and it requires some manual cleanup…
EDIT adding evidence because OP seems convinced that this code is not working because it is not possible to move things into the dbo schema. No, that is not the case, it’s just not possible to move dummy.floob -> dbo.floob if there’s already an object named dbo.floob. Note that it may not be a table!
Move all tables from dbo -> floob:
Results:
Move all tables back from floob -> dbo:
Results: