Solve the problem of "User, group, or role already exists in the current database" in the SQL Server database.

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

Problem scenarios

During SQL Server database migration, after recovering the database backup file on another Server, you need to recreate the user account on the database. When creating a login User, you must authorize the User in User Mapping for the specific database. Because the recovered database contains a User account with the same name, "User, group, or role already exists in the current database "error message. The error details are 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)

Previous solutions

Before creating a user account (or authorization), delete the user account with the same name in the corresponding database.

Latest Solution

Create a user account without authorization, and then associate the account with the corresponding database user using the following SQL statement. This avoids re-authorization.

USE {target database} EXEC sp_change_users_login 'Update _ one', '{existing username of the target database}', '{created username }'

Method Source

SQL Server Forums-How to assign a login to an existing user?

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.