We can use Update_one when the Database user name and login
name are different.
AutoFix can be used when both Database user name and login
name are same.
And auto fix can be used when login does not exist, if you
provide password new login will be created with the provided password, if you
have not passed any password, sql server will generate password then creates
the new login.
If a
login name does not exists, you would have to create it first before doing the
mapping. A quick way to do this is to use the following command which will
create the login and then map the login to the user.
--Command to map an
orphaned user to a login that is not present but will be created
EXEC
sp_change_users_login 'Auto_Fix', 'TestUser3', null,'pwd'
GO
Summarizing the T-SQL Used
In the
above process, the stored procedure sp_change_users_login is
used. The variable [ @Action ] specifies the exact use of this
stored procedure. It accepts a parameter as varchar(10) and can have one of the
following values:
- If parameter is Auto_Fix, database
user is mapped with same named SQL Server login. It may also create login,
if not present.
- If parameter is Report,
it lists the orphaned users and their security identifiers (SID).
- If parameter is Update_One, it
links the specified database user to an existing SQL Server login.
No comments:
Post a Comment