Automate new databases with role: db_datareader for sql user: readonly

  • Hello,

    I need to auto-role a user for every new database the role: db_datareader for the sql username: readonly.

    Is there a way I can automate this with a script?

    I want to automate this process to gain some time to do other useful things while working. Because I don't want developers to login and destroy the database if they do something wrong.

    If my message is unclear:

    - There is a SQL account named: readonly

    - This user should have access to all databases with the role: db_datareader

    - This user should also gain access to newly created databases.

    Can this be processed automatically with a script?

    Hope someone can help me out with this, I googled for hours but could not resolve this issue. There is also been a thread like this before by another user, however it looked like a different question.

    "http://www.sqlservercentral.com/Forums/Topic1115864-1526-1.aspx#bm1224030"

    Thank you

    Kind regards,

    Umit

  • You need to add this "ReadOnly" user to Model Database. That will serve the purpose. Every new database which is created on the server is actuly a copy of Model database only.

    1. Create a user for the ReadOnly login in Model database

    2. Add this user in the DB_DataReader role.

    You are done!!


    Sujeet Singh

  • Hello !

    Oh, now I know what Models is for, never knew it could be that easy.

    Thank you for your help ! Have a nice day 🙂

    Kind regards,

    Umit

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply