Problem scenarios
When you migrate a SQL Server database, you need to re-create the user accounts on the previous database after you restore the database backup files on another server. When you create a logged-on user, you need to authorize the user in user mapping for a specific database, and because a user account with the same name exists in the restored database, "user, group, or role already exists" will appear when created. Current database error prompt. Detailed error information is as follows:
Title:microsoft SQL Server Management Studio
------------------------------
Create failed for User ' testuser '. (MICROSOFT.SQLSERVER.SMO)
------------------------------
ADDITIONAL Information:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
User, group, or role ' testuser ' already exists in the current database. (Microsoft SQL Server, error:15023)
Before the solution
Before creating a user account (or authorization), delete the user account with the same name in the corresponding database.
The latest solution
Create a user account, do not authorize it, and then associate the user account with the corresponding database user through the following SQL statement. The advantage is that you avoid the unauthorized operation.
Use {target database}
EXEC sp_change_users_login ' update_one ', ' {target database already exists user name} ', ' {login username created} '
method source
SQL Server Forums-how to assign a login to a existing user?
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/