Udostępnij za pośrednictwem


sp_changedbowner (Transact-SQL)

Changes the owner of the current database.

Topic link iconTransact-SQL Syntax Conventions

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 an already existing SQL Server login or Microsoft Windows user. 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 assigned 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. This indicates that 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 that were previously assigned to dbo to this new database owner.

You can change the owner of any securable by using the ALTER AUTHORIZATION statement. For more information, see ALTER AUTHORIZATION (Transact-SQL).

Permissions

Requires TAKE OWNERSHIP permission on the database. If the new owner has a corresponding user in the database, requires IMPERSONATE permission on the login, otherwise requires CONTROL SERVER permission on the server.

Examples

The following example makes the login Albert the owner of the current database and maps to Albert existing aliases that are assigned to the old database owner.

EXEC sp_changedbowner 'Albert'

See Also

Reference

Security Stored Procedures (Transact-SQL)
CREATE DATABASE (Transact-SQL)
sp_dropalias (Transact-SQL)
sp_dropuser (Transact-SQL)
sp_helpdb (Transact-SQL)
sp_helplogins (Transact-SQL)
System Stored Procedures (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance