SQL Server error: User, group, or role ' XXX ' already exists in the current database. Error: 15023 workaround

Source: Internet
Author: User

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

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.