Changes the owner of an object in the current database.
|Applies to: SQL Server (SQL Server 2008 through current version).|
sp_changeobjectowner [ @objname = ] 'object' , [ @newowner = ] 'owner'
[ @objname = ] 'object'
Is the name of an existing table, view, user-defined function, or stored procedure in the current database. object is an nvarchar(776), with no default. object can be qualified with the owner of the existing object, in the form existing_owner.object if the schema and its owner have the same name.
[ @newowner=] 'owner '
Is the name of the security account that will be the new owner of the object. owner is sysname, with no default. owner must be a valid database user, server role, Microsoft Windows login, or Windows group with access to the current database. If the new owner is a Windows user or Windows group for which there is no corresponding database-level principal, a database user will be created.
0 (success) or 1 (failure)
sp_changeobjectowner removes all existing permissions from the object. You will have to reapply any permissions that you want to keep after running sp_changeobjectowner. Therefore, we recommend that you script out existing permissions before running sp_changeobjectowner. After ownership of the object has been changed, you can use the script to reapply permissions. You must modify the object owner in the permissions script before running.
To change the owner of a securable, use ALTER AUTHORIZATION. To change a schema, use ALTER SCHEMA.
Requires membership in the db_owner fixed database role, or membership in both the db_ddladmin fixed database role and the db_securityadmin fixed database role, and also CONTROL permission on the object.
The following example changes the owner of the
authors table to
EXEC sp_changeobjectowner 'authors', 'Corporate\GeorgeW'; GO