Adding a user with TSQL

  • Greetings folks. After 299 users added through EM, I promised myself I would make number 300 be the first I add strictly with TSQL. After an hour or two in BOL, this is what I came up with.

    USE FTTPVACMC

    GO

    EXEC sp_grantlogin 'us1\v123456'

    GO

    EXEC sp_grantdbaccess 'us1\v123456', 'Doe, Joe'

    GO

    EXEC sp_defaultdb 'us1\v123456','FTTPVACMC'

    GO

    EXEC sp_addrolemember 'Splicer', 'Doe, Joe'

    My questions are: 1) is this the right thing to do? 2) I tried it without using 'GO' after everything, and it worked, but the BOL examples used it, so I tried it and it also worked. What does using 'GO' do that not using it does not? 3) Is there a way to add more than one role at a time, or do I have to exec sp_addrolememeber once for every role?

    Greg

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • 'GO' is the batch terminator that tells whatever utility you're using (QA, sqlcmd, osql) to send the statements before it to SQL Server. Your stored procedures executed with or without 'GO' because they're self contained and you used 'EXEC'. Try running them without 'GO' and 'EXEC' and see what happens.

    sp_grantlogin 'us1\v123456'

    sp_grantdbaccess 'us1\v123456', 'Doe, Joe'

    sp_defaultdb 'us1\v123456','FTTPVACMC'

    sp_addrolemember 'Splicer', 'Doe, Joe'

    sp_addrolememeber will only add one at a time so you'll have to have to execute it for each role.

    Greg

    Greg

  • I was afraid of that, but thanks for the reply

    Greg

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

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

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