Home Forums SQL Server 2005 Backups How to change table owner when restoring database? RE: How to change table owner when restoring database?

  • Choose "Results to Text", then copy/paste the results into a new window.

    declare @OldOwner varchar(100), @NewOwner varchar(100)

    set @OldOwner = 'oldowner'

    set @NewOwner = 'dbo'

    select 'sp_changeobjectowner ''[' + table_schema + '].[' + table_name + ']'', ''' + @NewOwner + '''

    go'

    from information_schema.tables where Table_schema = @OldOwner

    You can skip the variables and hardcode the owner names in the script.