Error 21002: [SQL-DMO] user "XXX" already exists, how to solve it! Urgent !!!!
Delete XXX from database sysusers
Update:
Correspond login users to isolated database users
In fact, after we have created a database login user with the same name, we still cannot use the tables in the database because of the different Sid, that is, the user names in the system login table are the same as those in the Database User table, only the SID field is used. The SID value of the old system is used in the database. Therefore, we need to map it to the new one. The database uses the SID to identify users.
The stored procedure sp_change_users_login can be used here. It has three actions: Report, update_one, and auto_fix.
Run sp_change_users_login 'report'. The system lists the number of isolated users of the current database.
We only need to select the current database as testdb and then run
Sp_change_users_login 'Update _ one', 'test', 'test'
The system prompts you to fix an isolated user.
You can also use
Sp_change_users_login 'Auto _ fix', 'test', null, 'testpassword'
Create a user with the logon username "test" and the password "testpassword.
Now, the problem of accessing database objects has been solved. If multiple databases have data tables of the same user, you only need to select different databases and execute the update_one operation.