• Grey Twitter Icon
  • Grey Facebook Icon
  • Grey LinkedIn Icon
  • Grey Google+ Icon

© 2016 - 2019 All rights reserved. PigeonSQL.com | Filip Holub

Nested Cursor for sp_change_users_login

December 9, 2016

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:

 

 

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!

Please reload

RECENT POST
Please reload

  • Facebook Social Icon
  • Google+ Social Icon
  • LinkedIn Social Icon
  • Twitter Social Icon