SQL Server Mapping a user to a login and adding roles programmatically

Posted by user163457 on Stack Overflow See other posts from Stack Overflow or by user163457
Published on 2010-03-17T21:06:22Z Indexed on 2010/05/30 19:32 UTC
Read the original article Hit count: 195

In my SQL Server 2005 server I create databases and logins using Management Studio. My application requires that I give a newly created user read and write permissions to another database.

To do this I right-click the newly created login, select properties and go to User Mapping. I put a check beside the database to map this login to the db and select db_datareader and db_datawriter as the roles to map.

Can this be done programmatically? I've read about using Alter User and sp_change_users_login but I'm having problems getting these to work, since sp_change_users_login has been deprecated so I'd prefer to use Alter User.

Please note my understanding of SQL Server database users/logins/roles is basic

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql-server-2005