This is a simple piece of T-SQL code that allows you to change the ownership of all tables in a given database. In the example the ownership is being changed to “dbo” but that could be replaced with any owner andor schema you wanted.
It does use an undocumented stored procedure sp_MSforeachtable wich enumerates all the tables in the current database. There is also a sister stored procedure sp_MSforeachdb gives a DBA the ability to cycle through every database in your catalog. I find this one particulalry useful when running certain DBCC comands such as checkdb.
sp_MSforeachtable @command1=”EXEC sp_changeobjectowner ‘?’,’dbo’”