Collapse the table of content
Expand the table of content


SQL Server 2000

Maps a login to a user in a database. sp_addalias is provided for backward compatibility. Microsoft® SQL Server™ version 7.0 provides roles and the ability to grant permissions to roles as an alternative to using aliases.


sp_addalias [ @loginame = ] 'login'
[ @name_in_db = ] 'alias_user'


[ @loginame = ] 'login'

Is the name of the login to be aliased. login is sysname with no default. login must be a valid SQL Server login or Microsoft Windows NT® user with permission to connect to SQL Server. login cannot already exist or be aliased to an existing user in the database.

[ @name_in_db = ] 'alias_user'

Is the name of the user the login is mapped to. alias_user is sysname, with no default. alias_user must be a valid Windows NT or SQL Server user in the database in which the login is aliased. When specifying Windows NT users, specify the name the Windows NT user is known by in the database (added using sp_grantdbaccess).

Return Code Values

0 (success) or 1 (failure)


A login can be mapped to users in any database. Execute sp_addalias only in the database in which the user must be aliased. When users connect to SQL Server with login, they can perform activities in the database under the permissions applied to alias_user.

Note  The sa login cannot be aliased.

A login can use a database if:

  • The login has an associated user account in the database.

  • The login has a user alias in the database, which has been added by the database owner or member of the sysadmin fixed server role with sp_addalias.

  • The guest account has been added to the database.

sp_addalias cannot be executed from within a user-defined transaction.

The table shows several system stored procedures used in conjunction with sp_addalias.

Stored procedure Description
sp_helplogins Returns a list of valid login values.
sp_helpuser Returns a list of valid alias_user values in the database in which the login is used.
sp_dropalias Removes an alias mapping.


Only members of the sysadmin fixed server role, and the db_accessadmin and db_owner fixed database roles can execute sp_addalias.


This example allows the SQL Server login Victoria, which is not a user in the current database, to use the current database and alias Victoria to an existing user (Albert) in the current database.

EXEC sp_addalias 'Victoria', 'Albert'

See Also







System Stored Procedures

© 2015 Microsoft