Execute sql on all sqlserver instances

  • Hi,

    I have 12 instances in my server. How can I execute tsql on all sqlserver instances for one database? (I have linked servers from one of my servers say SGTilt\Gears).

    Thanks in advance.

    Prakash


    Kindest Regards,

    R

  • declare @server nvarchar(200)

    declare @strsql nvarchar(2000)

    declare curs1 cursor for select datasource from master..sysservers

    open curs1

    fetch next from curs1 into @server

    while @@fetch_status=0

    begin

    set @strsql='select * from '+@server+'.master.dbo.sysusers'

    --set @strsql=@server+'.master..sp_who2'--proc version

    exec @strsql

    fetch next from curs1 into @server

    end

    close curs1

    deallocate curs1

    MVDBA

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

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