SQL Server – Error 15023: User already exists in current database



Alright, cause this troubles me regularly when restoring databases… 😉 If you ever encounter Error 15023: User already exists in current database you need to use sp_change_users_login to map an existing database user to a SQL Server login.









sp_change_users_login [ @Action = ] ‘action’
     [ , [ @UserNamePattern = ] ‘user’ ] 
     [ , [ @LoginName = ] ‘login’ ] 
         [ , [ @Password = ] ‘password’ ]


HTHs


Daniel

Comments (4)

  1. ernst says:

    ja ja, immer wieder, nicht wahr? Bin dazu übergegangen, den Haupt-Benutzer in allen Custumer-DBs mit fixer SID anzulegen…

  2. Well, to be honest that’s actually quite easy, nevertheless I keep forgetting it all the time (pretty

  3. Fareed says:

    What am I supposed to give in single quote for action – should I change it with some name or leave it as it is?

  4. sql dummy says:

    never use sql before and trying to learn it. Would have preferred a more detailed example of this example. 🙁