Sp_changeobjectowner changes the owner of the object in the current database.
Grammar:
sp_changeobjectowner [ @objname = ] 'object' ,
[ @newowner = ] 'owner'参数[@objname =] '
Object ' The name of an 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 the form:
existing_owner.object。[@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). The return code value of 0 (successful) or 1 (failed) annotation 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 can only be performed if the sysadmin fixed server role and the db_owner fixed database role are members, or are members of both the db_ddladmin fixed database role and the db_securityadmin fixed database role sp_ Changeobjectowner.
Example the following example changes the owner of the authors table to:
CorporateGeorgeW。EXEC sp_changeobjectowner
'authors', 'CorporateGeorgeW'
exec sp_changeobjectowner 'ychw.
proc_Subject512_Function', 'dbo'