sp_changeobjectowner (Transact-SQL)sp_changeobjectowner (Transact-SQL)

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

更改当前数据库中对象的所有者。Changes the owner of an object in the current database.

重要

此存储过程仅适用于中MicrosoftMicrosoft SQL Server 2000 (8.x)SQL Server 2000 (8.x)可用的对象。This stored procedure only works with the objects available in MicrosoftMicrosoftSQL Server 2000 (8.x)SQL Server 2000 (8.x). 此功能处于维护模式并且可能会在 Microsoft SQL Server 将来的版本中被删除。This feature is in maintenance mode and may be removed in a future version of Microsoft SQL Server. 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。Avoid using this feature in new development work, and plan to modify applications that currently use this feature.请改用ALTER SCHEMAalter AUTHORIZATIONUse ALTER SCHEMA or ALTER AUTHORIZATION instead. sp_changeobjectowner同时更改架构和所有者。sp_changeobjectowner changes both the schema and the owner. 若要保持与早期版本 SQL ServerSQL Server 的兼容性,如果当前所有者和新所有者拥有的架构名称与它们的数据库用户名相同,则此存储过程将只更改对象所有者。To preserve compatibility with earlier versions of SQL ServerSQL Server, this stored procedure will only change object owners when both the current owner and the new owner own schemas that have the same name as their database user names.

重要

已经将新的权限要求添加到此存储过程。A new permission requirement has been added to this stored procedure.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

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

参数Arguments

[ @objname = ] 'object'当前数据库中现有的表、视图、用户定义函数或存储过程的名称。[ @objname = ] 'object' Is the name of an existing table, view, user-defined function, or stored procedure in the current database. 对象是一个nvarchar (776),无默认值。object is an nvarchar(776), with no default. 对象可以用现有对象的所有者限定,格式为_existing_owner_ 如果架构及其所有者具有相同的名称,则为_对象_。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_ '将成为对象的新所有者的安全帐户的名称。[ @newowner = ] 'owner_ ' Is the name of the security account that will be the new owner of the object. 所有者sysname,无默认值。owner is sysname, with no default. 所有者必须是有权访问当前数据库的有效数据库MicrosoftMicrosoft用户、服务器角色、Windows 登录名或 windows 组。owner must be a valid database user, server role, MicrosoftMicrosoft Windows login, or Windows group with access to the current database. 如果新所有者是没有对应数据库级主体的 Windows 用户或 Windows 组,则将创建数据库用户。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.

返回代码值Return Code Values

0(成功)或 1(失败)0 (success) or 1 (failure)

备注Remarks

sp_changeobjectowner从对象中删除所有现有权限。sp_changeobjectowner removes all existing permissions from the object. 在运行sp_changeobjectowner后,您必须重新应用想要保留的任何权限。You will have to reapply any permissions that you want to keep after running sp_changeobjectowner. 因此,建议您在运行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.

若要更改安全对象的所有者,请使用 ALTER AUTHORIZATION.To change the owner of a securable, use ALTER AUTHORIZATION. 若要更改架构,请使用 ALTER SCHEMA。To change a schema, use ALTER SCHEMA.

权限Permissions

需要db_owner固定数据库角色的成员身份,或者db_ddladmin固定数据库角色和db_securityadmin固定数据库角色的成员身份,同时还要求对对象拥有 CONTROL 权限。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.

示例Examples

下面的示例将authors表的所有者更改为。 Corporate\GeorgeWThe following example changes the owner of the authors table to Corporate\GeorgeW.

EXEC sp_changeobjectowner 'authors', 'Corporate\GeorgeW';  
GO  

另请参阅See Also

ALTER SCHEMA (Transact-sql) ALTER SCHEMA (Transact-SQL)
ALTER DATABASE (Transact-sql) ALTER DATABASE (Transact-SQL)
ALTER AUTHORIZATION (Transact-SQL) ALTER AUTHORIZATION (Transact-SQL)
sp_changedbowner (Transact-sql) sp_changedbowner (Transact-SQL)
系统存储过程 (Transact-SQL)System Stored Procedures (Transact-SQL)