Objects | data | database sp_changeobjectowner
Changes the owner of an object in the current database.
Grammar
sp_changeobjectowner [@objname =] ' object ', [@newowner =] ' owner '
Parameters
[@objname =] ' Object '
The name of the existing table, view, or stored procedure in the current database. Object has a data type of nvarchar (517) and no default value. Object can be qualified with an existing object owner, in existing_owner.object format.
[@newowner =] ' Owner '
The name of the security account that is about to become the new owner of the object. Owner's data type is sysname, and there is no default value. Owner must be a valid Microsoft®sql Server™ user or role or Microsoft Windows NT® user or group in the current database. When you specify a Windows NT user or group, specify the name that the Windows NT user or group has known in the database (added with sp_grantdbaccess).
Return code value
0 (Success) or 1 (failed)
Comments
The object owner (or a member of the group or role that owns the object) has special permissions on the object. The object owner can execute any Transact-SQL statement related to the object (such as INSERT, UPDATE, DELETE, SELECT, or EXECUTE), or you can manage the permissions of the object.
If the security account that owns the object must be dropped, but you want to keep the object at the same time, use Sp_changeobjectowner to change the object owner. This procedure deletes all existing permissions from the object. After you run sp_changeobjectowner, you need to reapply any permissions that you want to keep.
For this reason, it is recommended that you write scripts for existing permissions before running Sp_changeobjectowner. Once you have changed the ownership of an object, you may want to reapply the permissions using the script. You need to modify the object owner in the permissions script before running the script. For more information about writing database scripts, see Writing database Documents and scripts.
You can use Sp_changedbowner to change the owner of the database.
Permissions
Sp_changeobjectowner can only be performed if the sysadmin fixed server role and the db_owner fixed database role are members, or both the db_ddladmin fixed database role and the db_securityadmin fixed database role.
Example
The following example changes the owner of the authors table to Corporate\GeorgeW.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.