top of page
  • Twitter Social Icon
  • Facebook Social Icon
  • LinkedIn Social Icon
Search

Nested Cursor for sp_change_users_login

  • Writer: Filip Holub
    Filip Holub
  • Dec 9, 2016
  • 1 min read

Every DBA knows this Error:

"Error 15023: User already exists in current database."

For example: When I backup some database from production environment and then I want to restor it in a testing environment and in the end I need to set permission for some users, this error appears "15023".

How to fix this?

We can use system stored procedures "sp_change_users_login".

Therefore, I created Nested Cursor, that generates sp_change_users_login for every database and for each users. It looks like this:

sp_change_users_login | Auto_Fix

This script saves me a lot of time because I restore some DB on TEST, DEV or UAT environment very often.

As you can see below:

I hope this article helps!

 
 
 

Comments


RECENT POST
  • Grey Twitter Icon
  • Grey Facebook Icon
  • Grey LinkedIn Icon

© 2020 All rights reserved. PigeonSQL.com | Filip Holub

bottom of page