This script will change the table owner from the old owner to the default DBO owner. This usually needs to be done when you move your database from one hosting provider to another or to your own server.
Open SQL Server Management Studio Right-Click on the database and choose [New Query] Next, paste the following code and edit the [currentOwner] and the [newOwner] values. (New Owner is usually dbo) Next, click the [Execute] button
DECLARE @currentObject nvarchar(517)
DECLARE @qualifiedObject nvarchar(517)
DECLARE @currentOwner varchar(50)
DECLARE @newOwner varchar(50)
SET @currentOwner = 'Old_Owner_Name'SET @newOwner = 'dbo'
DECLARE alterOwnerCursor CURSOR FOR
SELECT [name] FROMdbo.sysobjectsWHERE xtype = 'U'or xtype = 'P'ANDLEFT([name], 2) <> 'dt'
OPEN alterOwnerCursor
FETCH NEXT FROM alterOwnerCursor INTO @currentObject
WHILE FETCH_STATUS = 0
BEGIN
SET @qualifiedObject = CAST(@currentOwner as varchar) + '.' + CAST(@currentObject as varchar)EXEC sp_changeobjectowner @qualifiedObject, @newOwner
FETCH NEXT FROM alterOwnerCursor INTO @currentObject
END
CLOSE alterOwnerCursor
DEALLOCATE alterOwnerCursor