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'
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:
sp_addalias cannot be executed from within a user-defined transaction.
The table shows several system stored procedures that can be 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 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'
sp_addlogin | sp_helplogins |
sp_addrole | sp_helpuser |
sp_adduser | System Stored Procedures |
sp_dropalias |