I am attempting to create T-SQL that I can re-use on different db’s, users, domains, roles, etc…
The trouble I’m having is when trying to change database names dynamically. I need the ability to hit multiple db’s in one shot. My goal for starters is to only change the username parameter for each user/executio and execute the rest.
I have attached the code. Any suggestions would be helpful - there must be a better way.
This is what’s failing after adding the +(@DB) variable:
set @USER = + QUOTENAME(@DB) + 'CREATE USER ' + QUOTENAME(@DN + @UN) + ' FOR LOGIN ' + quotename(@DN + @UN) + ' WITH DEFAULT_SCHEMA=[' + @DN + @UN + ']' --db1