How to troubleshoot the SQL Server database "User, group, or role already exists

Source: Internet
Author: User
Tags microsoft sql server management studio microsoft sql server management studio sql server management sql server management studio

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.