Maps a login to a user in a database.
|sp_addalias provides compatibility with earlier versions of SQL Server. This feature will be removed in the next version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. As an alternative to using aliases, the SQL Server 2005 Database Engine provides roles and the ability to grant permissions to roles. For more information, see CREATE USER (Transact-SQL) and CREATE ROLE (Transact-SQL).|
- [ @loginame = ] 'login'
Is the name of the login to which an alias will be assigned. login is sysname with no default. login must be a valid SQL Server login or Microsoft Windows user with permission to connect to an instance of the SQL Server. login cannot already exist or be assigned as an alias to an existing user in the database.
- [ @name_in_db = ] 'alias_user'
Is the name of the user to which the login is mapped. alias_user is sysname with no default. alias_user must be a user in the database in which the login is aliased. When you map to a Windows user, specify the name by which it is known in the database.
A login can be mapped to users in any database. Execute sp_addalias only in the database in which the user must have an alias. When users connect to an instance of the Database Engine by using the login parameter, they can perform activities in the database under the permissions applied to alias_user.
|You cannot create an alias for the sa login.|
A login can access a database under the following circumstances:
The login has an associated user account in the database.
The login has a user alias in the database, which the database owner or a member of the sysadmin fixed server role has added by using sp_addalias.
The guest account has been enabled in the database.
The sp_addalias stored procedure cannot be executed from a user-defined transaction.
The following table shows several system stored procedures that can be used in conjunction with sp_addalias.
Returns a list of valid login values.
Returns a list of valid alias_user values in the database in which the login is used.
Removes an alias mapping.
The following example shows how to map SQL Server login
Victoria to an existing user (
Albert) in the
USE AdventureWorks; EXEC sp_addalias 'Victoria', 'Albert' ;
ReferenceSecurity Stored Procedures (Transact-SQL)
CREATE USER (Transact-SQL)
CREATE ROLE (Transact-SQL)
System Stored Procedures (Transact-SQL)