SQLServer name Parameter - Create login RRS feed

  • Question

  • User-2099569815 posted

    Hi there experts,

    I have given a task to create database login for a given set of database server. Rather than creating user manually going to each server,

    i was hoping to write a script to create login for all server at once.

    I am using cursor to get the server but the syntax to create login not sure where to pass this servername so that login gets created for and on each of the server and not

    only on a local server.

    here is my script and which only creates login for/on a server where i am running script from:

    declare @dbservername varchar(50)
    declare @dbname varchar(60)
    declare svrname cursor for
    select servername from mylist 
    open svrname
    fetch next from svrname into @dbservername
    while @@FETCH_STATUS = 0
    print @dbservername
    create login test with password = 'test'
    --from windows
    fetch next from svrname into @dbservername
    close svrname
    deallocate svrname


    Thursday, April 21, 2016 5:36 PM

All replies