Changing a table owner

前端 未结 5 1312
名媛妹妹
名媛妹妹 2021-02-04 00:21

I\'m trying to change the owner of a table:

sp_changeobjectowner \'OWNER.TABLENAME\', \'dbo\'

But when executing I get the error message:

5条回答
  •  星月不相逢
    2021-02-04 01:22

    To cover the case where a table exists within a constructed schema name like 'Common' (that is not related to a username), then it is the schema owner that needs to be changed.

    alter authorization on schema::Common TO dbo;
    

    That will change the objects within the schema to the specified owner 'dbo' and keep the table within 'Common'.

    To list schema owners:

    select db_name() as Db, 
           sch.name as SchemaName, 
           u.Name as Owner
      from sys.schemas sch
      join sys.sysusers u
        on u.uid = sch.principal_id;
    

提交回复
热议问题