background : When you recently migrated SQL Server database 2008, when you created a user mapping. SQL Server error: User, group, or role ' XXX ' already exists in the current database. Error: 15023.
here 's how to fix it.
650) this.width=650; "title=" QQ picture 20160908093002 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "alt=" QQ picture 20160908093002 " Src= "Http://s3.51cto.com/wyfs02/M00/86/FE/wKioL1fQ263gHxP-AAC9AeMM2I8850.png" border= "0" height= "188"/>
Analysis :
When you restore a database to a different server, the database contains a set of users and permissions, but there may not be a corresponding login or the user associated with the login may not be the same user.
This situation is known as "orphaned users". At this point, you cannot resolve the logon issue by creating a new login or by granting the user permission to the corresponding database for a login with the same name.
Because SQL Server will report "error 15023: User or role already exists in the current database",
Simple to understand :
The database backup file already contains the user test, the database is now restored, and then found that the existing database does not have the test user, want to create a new test user, as the owner of the database, this problem occurs.
It can be understood that logins and users are two different concepts, although the names are the same. When you create a new login, you do not get an error if you do not add the database map. Adding a database map is equivalent to adding a user with the same name to the database.
However, there is already a test user, so this will be an error.
Workaround :
You can resolve the problem by using the following methods.
1. Create a new test login name, but do not add a database mapping.
2. Use the script to associate the orphaned user test to the login test:
Use [database name]
Go
Sp_change_users_login ' Update_One ', ' Test ', ' test '
SQL Server error: User, group, or role ' XXX ' already exists in the current database. Error: 15023 workaround