Export (0) Print
Expand All
Expand Minimize

sp_changeobjectowner

SQL Server 2000

  New Information - SQL Server 2000 SP3.

Changes the owner of an object in the current database.

Syntax

sp_changeobjectowner [ @objname = ] 'object' , [ @newowner = ] 'owner'

Arguments

[@objname =] 'object'

Is the name of an existing table, view, user-defined function, or stored procedure in the current database. object is nvarchar(517), with no default. object can be qualified with the existing-object owner, in the form existing_owner.object.

[@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 Microsoft® SQL Server™ user or role, or Microsoft Windows NT® user or group in the current database. When specifying Windows NT users or groups, specify the name the Windows NT user or group is known by in the database (added using sp_grantdbaccess).

Return Code Values

0 (success) or 1 (failure)

Remarks

The owner of an object (or the members of the group or role owning the object) has special permissions for the object. Object owners can execute any of the Transact-SQL statements related to the object (for example, INSERT, UPDATE, DELETE, SELECT, or EXECUTE) and can also manage the permissions for the object.

Use sp_changeobjectowner to change the owner of an object if the security account that owns the object has to be dropped but the object must be retained. This procedure removes all existing permissions from the object. You will need to reapply any permissions you want to keep after running sp_changeobjectowner.

For this reason, it is recommended that you script out existing permissions before running sp_changeobjectowner. Once ownership of the object has been changed, you may use the script to reapply permissions. You will need to modify the object owner in the permissions script before running. For more information about database scripting, see Documenting and Scripting Databases.

Use sp_changedbowner to change the owner of a database.

Permissions

Only members of sysadmin fixed server role, the db_owner fixed database role, or a member of both the db_ddladmin and db_securityadmin fixed database roles can execute sp_changeobjectowner.

Examples

This example changes the owner of the authors table to Corporate\GeorgeW.

EXEC sp_changeobjectowner 'authors', 'Corporate\GeorgeW'

See Also

CREATE TABLE

sp_changedbowner

System Stored Procedures

Show:
© 2014 Microsoft