Maps one user to another in a database.
sp_addalias login_id, username
where
Executing sp_addalias maps one user (login_id) to another (login_id) in the current database. The mapping is shown in sysalternates, where the two users' suids are connected.
A report on any users mapped to a specified user can be generated with the sp_helpuser system stored procedure if you give the specified login ID as a parameter.
When a user tries to use a database, SQL Server checks sysusers to see if the login ID is listed there. If the login ID is not there, it then checks sysalternates. If an entry (the user's suid) is found there. and it is mapped to a database user's suid (altsuid in sysalternates table), the first user is treated as the second user while using the database.
There are three ways that a user can be authorized to use a database (assuming the user is listed in master.dbo.syslogins).
In this example, there is a user named Albert in the current database's sysusers table and a login ID for a user ID Victoria in master.dbo.syslogins. The sp_addalias system stored procedure allows Victoria to use the current database and to be known as Albert in that database.
sp_addalias Victoria, Albert
Execute permission defaults to the database owner.
master.dbo.syslogins, sysalternates, sysusers
sp_addlogin | sp_helpuser |
sp_adduser | USE |
sp_dropalias |