MSSQL table owner for restore

--Restore from file or on attach

---------------------------------------------------------
DECLARE tabcurs CURSOR
FOR
    SELECT 'intranet.' + [name]
      FROM sysobjects
     WHERE xtype = 'u'

OPEN tabcurs
DECLARE @tname NVARCHAR(517)
FETCH NEXT FROM tabcurs INTO @tname

WHILE @@fetch_status = 0
BEGIN

    EXEC sp_changeobjectowner @tname, 'intranet2'

    FETCH NEXT FROM tabcurs INTO @tname
END
CLOSE tabcurs
DEALLOCATE tabcurs
---------------------------------------------------------
--?--EXEC sp_changeobjectowner 'intranet.AllocObjectId', 'intranet2';
---------------------------------------------------------