如何修改SQL SERVER的数据库拥有者及表拥有者?

华南虎哥 2001-11-26 01:39:00
谢谢!
...全文
270 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shinebei 2001-11-26
  • 打赏
  • 举报
回复
sp_changeobjectowner
更改当前数据库中对象的所有者。

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

参数
[@objname =] 'object'

当前数据库中现有的表、视图或存储过程的名称。object 的数据类型为 nvarchar(517),没有默认值。object 可用现有对象所有者限定,格式为 existing_owner.object。

[@newowner =] 'owner'

即将成为对象的新所有者的安全帐户的名称。owner 的数据类型为 sysname,没有默认值。owner 必须是当前数据库中有效的 Microsoft® SQL Server™ 用户或角色或 Microsoft Windows NT® 用户或组。指定 Windows NT 用户或组时,请指定 Windows NT 用户或组在数据库中已知的名称(用 sp_grantdbaccess 添加)。

返回代码值
0(成功)或 1(失败)

注释
对象所有者(或拥有对象的组或角色的成员)对对象有特殊的权限。对象所有者可以执行任何与对象有关的 Transact-SQL 语句(例如 INSERT、UPDATE、DELETE、SELECT 或 EXECUTE),也可以管理对象的权限。

如果拥有对象的安全帐户必须要除去,但同时要保留该对象,请使用 sp_changeobjectowner 更改对象所有者。该过程从对象中删除所有现有权限。在运行 sp_changeobjectowner 之后,需要重新应用要保留的任何权限。

由于这个原因,建议在运行 sp_changeobjectowner 之前,编写现有权限的脚本。一旦更改了对象的所有权,可能要使用该脚本重新应用权限。在运行该脚本之前需要在权限脚本中修改对象所有者。有关编写数据库脚本的更多信息,请参见编写数据库文档和脚本。

可以使用 sp_changedbowner 更改数据库的所有者。

权限
只有 sysadmin 固定服务器角色和 db_owner 固定数据库角色成员,或既是 db_ddladmin 固定数据库角色又是 db_securityadmin 固定数据库角色的成员,才能执行 sp_changeobjectowner。

示例
下面的示例将 authors 表的所有者改为 Corporate\GeorgeW。

EXEC sp_changeobjectowner 'authors', 'Corporate\GeorgeW'
nononono 2001-11-26
  • 打赏
  • 举报
回复
sp_changedbowner (T-SQL)
Changes the owner of the current database.

Syntax
sp_changedbowner [@loginame =] 'login' [,[@map =] remap_alias_flag]

Arguments
[@loginame =] 'login'
Is the login ID of the new owner of the current database. login is sysname, with no default. login must be Microsoft® SQL Server™ login or a Microsoft Windows NT® user that already exists. login cannot become the owner of the current database if it already has access to the database through an existing alias or user security account within the database. To avoid this, drop the alias or user within the current database first.
[@map =] remap_alias_flag
Is the value true or false, which indicates whether existing aliases to the old database owner (dbo) are mapped to the new owner of the current database or dropped. remap_alias_flag is varchar(5), with a default of NULL, indicating any existing aliases to the old dbo are mapped to the new owner of the current database. false indicates that existing aliases to the old database owner are dropped.
Return Code Values
0 (success) or 1 (failure)

Remarks
After sp_changedbowner is executed, the new owner is known as the dbo user inside the database. The dbo has implied permissions to perform all activities in the database.

The owner of the master, model, or tempdb system databases cannot be changed.

To display a list of the valid login values, execute the sp_helplogins stored procedure.

Executing sp_changedbowner with only the login parameter changes database ownership to login and maps the aliases of users who were previously aliased to dbo to the new database owner.

Permissions
Only members of the sysadmin fixed server role or the owner of the current database can execute sp_changedbowner.

Examples
This example makes the user Albert the owner of the current database and maps existing aliases to the old database owner to Albert.

EXEC sp_changedbowner 'Albert'



See Also
CREATE DATABASE sp_helpdb
sp_dropalias sp_helplogins
sp_dropuser System Stored Procedures

nononono 2001-11-26
  • 打赏
  • 举报
回复
sp_changeobjectowner (T-SQL)
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, 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.

Use sp_changedbowner to change the owner of a database.

Permissions
Only members of 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 System Stored Procedures
sp_changedbowner
相关推荐
发帖
MS-SQL Server

3.4w+

社区成员

MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
帖子事件
创建了帖子
2001-11-26 01:39
社区公告
暂无公告