On other computers, you will not be prompted to use-->sp_change_users_login to eliminate orphaned users of SQL Server when you have a copy of the repository on the original server

Source: Internet
Author: User

Every time a database is backed up from the server (SQL Server database), if you restore the backup database file locally, there will always be a problem with user permissions.

After many experiments, I found that there is a statement that can play a role, that is, the sp_change_users_login statement.

Specific usage:
EXEC sp_change_users_login ' update_one ', ' username ', ' login name ';

Expansion:

An orphaned account is a database in which the account has only a user name and no login, so that the user exists in the sysusers system table in the user library and there is no corresponding record in the syslogins of the master database.

Orphaned accounts are typically produced in two ways:

1. Restore the backed-up database on another machine to restore the database from the other server, the logins are created independently (not copied from other servers), and the orphaned user is created.

2. After reloading the system or SQL Server, only the user library is restored

The workaround is to use sp_change_users_login to fix it.

There are three ways to use sp_change_users_login

Usage 1:exec sp_change_users_login ' report ' lists orphaned users of the current database

Usage 2:exec sp_change_users_login ' auto_fix ', ' username ' can automatically add a login with the same name as the user name to the syslogins

Usage 3:exec sp_change_users_login ' update_one ', ' username ', ' login ' to map the user name to the specified login name.

On other computers, you will not be prompted to use-->sp_change_users_login to eliminate orphaned users of SQL Server when you have a copy of the repository on the original server

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.