Is there a way to directly copy the User Mapping from one SQL Server login to another using SQLCMD?
In SQL Server Management Studio Object Explorer | (local) | Security | Logins, Right-Click a user (e.g: BUILTIN\Administrators | User Mapping, I'm looking for a way to copy all the related information in that window from one account to a newly created one.
The main reason I need to use SQLCMD is I'm looking to place this in a script.
Best Answer
I'd recommend using sp_MSforeachdb to do this - it executes a SQL script against all databases defined in master. Your code is going to look something like the following:
The script to copy permissions from one user to another is a bit long for here, but an example that I found is here: http://vyaskn.tripod.com/scripting_permissions_in_sql_server_2005.htm
If you save that in a .sql script, then run it using SQLCMD or in SSMS, you should see what I think you're looking for.