OK, First it's probably important to state that i'm a noob so please forgive me for any incorrect terminology or misconceptions.
My problem is this, I have a database that I run a restore on periodically and every time I run this restore it resets some user mappings that I have to go in and manually change. I would like to script this change.
This is what I currently have
USE profile
Drop User [<UserName>]
GO
Create User [<UserName>] For LOGIN [<UserName>]
GO
exec sp_addrolemember 'db_owner', 'UserName'
GO
This will work for accounts that are actually DataBase user Accounts. Although the account I am trying to fix/modify is actually a master account and is not linked to any database specifically.
Just in case my terminology is confusing i'll explain a little more. If you're looking at the object explorer in SQL Server. The account lives under ServerName>Security>Logins.
Not under ServerName>Database>DatabaseName>Security>Users.
Please let me know if I wasn't clear or more info is needed.