Database Backup restoration prompt: 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

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)


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.

-Shrink SQL code

USE {target database}
EXEC sp_change_users_login 'update _ one', '{username already exists in the target database}', '{username created }'


Another solution

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

The owner of the restored database is an isolated user.

Query analyzer execution:

Exec sp_change_users_login 'report'

Find isolated users

Exec sp_changedbowner 'sa'

The database owner (dbo) is a non-isolated user.

EXEC sp_MSforeachtable 'exec sp_changeobjectowner ''? '', ''Dbo '''

Change the owner of other tables to the database owner (dbo)

Other isolated users can be deleted or processed by themselves.

Delete an isolated user:

1. Open the Enterprise Manager, expand the server, right-click the local server, and choose Properties:

2. Select the server settings tab and select allow direct modification to the system directory.

3. Open the database system table sysusers, right click -- open table -- return all rows

4. Select the user to be added for restoration, find the relevant row, and right-click to delete

5. You can directly modify and restore the system directory.

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.