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

  • homebrew01 (9/14/2010)


    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.

    This method should work for you. I recommend checking all of the records returned by the query - sanity check.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events