Our non production servers have information refreshed into them on a regular basis from production. The way this is done is to do a full backup of production, then restore it onto the non-production SQL Server. This has the undesired effect of overwriting all of the permissions for users.
I have been trying to find a method to pull those permissions out of the database in the form of a script. That way when the database is refreshed, I can run the script against the newly refreshed database and restore the permissions.
I tried to find the data in sys.database_principals and sys.database_permissions, but my SQL-fu isn’t good enough to make this data into something usable.
What’s the best method to get this data out?
K. Brian Kelley has a pretty good script for this at SQLServerCentral.
You can also try some of the “Related” links on the right of this page.