How to change default database for multiple users (logins) at once?

  • Hello!

    I am trying write a sql script to change the default database to master for multiple users at once.

    The following code allows me to change the default database for one user:

    ALTER LOGIN [DOMAIN\login]

    WITH DEFAULT_DATABASE = master

    However, for efficiency, I am trying to change the default database for multiple users at once.

    Any help is highly appreciated.

    Thank you,

    MK

  • You have to execute the command once for each user, but you can have multiple commands in your script.

  • Multiple commands in the same script will do ...

  • Multiple commands in the same script will do ...

  • Thank you very much for all those you replied back to my request. I will try your suggestions.

    MK

  • I was wondering whether someone could help me with creating a loop to iterate through a table (sys.syslogins) and

    change the default databases to a different database for all sql logins. If successful, the users should be directed to the newly

    selected database at logon. We have nearly 150 users that login to the server.

    Thank you,

    MK

Viewing 6 posts - 1 through 5 (of 5 total)

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