TSQL about more Servers

  • Hello

    I have an SQL-Server 2008 management server from witch I start a TSQL like that:

    EXEC sp_MSforeachdb @command1 = 'select * from ?.sys.database_files'

    How I do this for more Servers?

    I tried with this command, but it doesn't run:

    USE Server1.master

    EXEC sp_MSforeachdb @command1 = 'select * from ?.sys.database_files'

    I configured a linked server to Server1.

    Thanks a lot

    miller

  • This command doesn't run too:

    EXEC sp_MSforeachdb @command1 = 'select * from srvdentw.?.sys.database_files'

  • If you tell us what "doesn't run" means we should be able to help you better.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • mick miller (6/14/2009)


    USE Server1.master

    USE statement only works for local databases. Try callin' like this:

    EXECUTE Server1.master.sys.sp_msforeachdb 'PRINT ''?'''

    This requires RPC to be enabled.

    Another option would be a hack by using OPENQUERY.

    Flo

  • Msg 7314, Level 16, State 1, Line 1

    The OLE DB provider "SQLNCLI10" for linked server "srvdentw" does not contain the table ""model"."sys"."database_files"". The table either does not exist or the current user does not have permissions on that table.

    the linked server user is the same user as the service is started on remote sql-server

    thanks miller

  • Hello

    EXECUTE srvdentw.master.sys.sp_msforeachdb 'PRINT ''?'''

    Msg 7411, Level 16, State 1, Line 1

    Server 'srvdentw' is not configured for RPC.

    Thanks miller

  • mick miller (6/14/2009)


    Hello

    EXECUTE srvdentw.master.sys.sp_msforeachdb 'PRINT ''?'''

    Msg 7411, Level 16, State 1, Line 1

    Server 'srvdentw' is not configured for RPC.

    Thanks miller

    Either turn on RPC, or try it like this:

    EXEC ('EXECUTE master.sys.sp_msforeachdb ''PRINT ''''?'''''''') AT srvdentw

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Wow! Never saw this syntax. Thanks Barry! 🙂

    @mick miller: I think EXECUTE AT should be the most simple solution.

    Flo

  • I always try to avoid linked servers !

    With sql2008 SSMS you can connect to a server group and execute a centrain sql script at onece on the whole group !!

    This is a very cool feature ! (Check books online)

    Off course you could also SQLCMD to connect to your # servers and collect the data you want.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Florian Reischl (6/14/2009)


    Wow! Never saw this syntax. Thanks Barry! 🙂

    Thanks, Flo. It's in BOL, but I think that I learned it from Erland's blog.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • ALZDBA (6/14/2009)


    With sql2008 SSMS you can connect to a server group and execute a centrain sql script at onece on the whole group !!

    This is a very cool feature ! (Check books online)

    Oooh, great idea Alz, I forgot this was SQL 2008!

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • thanks for all ideas and answers!

    @alzdba

    I made a ServerGroup and a lot of server registrations:

    ServerGroupI

    - Srvdw

    - Srvdw1

    - Srvdentw

    - ...

    I can use a query over the group now, that's very cool!

    question I:

    Why does I have some errors with following tsql, see attachments?

    EXEC sp_MSforeachdb @command1 = 'select name, physical_name, state_desc, size, max_size, growth from ?.sys.database_files'

    question II:

    How I can write the result into a table (for the first run to create the table) like that?

    select *into zzdbfiles.dbfiles

    from OPENQUERY([srsql1],'EXEC sp_MSforeachdb @command1 = ''select name, physical_name, state_desc, size, max_size, growth from ?.sys.database_files''')

    second and more runs:

    insert into table zzdbfiles.dbfiles

    from OPENQUERY([srsql1],'EXEC sp_MSforeachdb @command1 = ''select name, physical_name, state_desc, size, max_size, growth from ?.sys.database_files''')

    thanks for your support

    miller

  • Sorry for the alte response, I lost track of this thread :blush:

    - In what way does your SRVDW(dom\sadb) differ from your other servers ?

    - Are these databases in a lower level db-mode ?

    Johan

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Thats no problem!

    This is the domain- and username (dom)\sadb. That isn't a DB.

    srwebfactory(dom\sadb): An error occurred while executing batch. Error message is: This server returned a fewer number of result sets than other responding servers. This may impact the ability to properly merge results.

    I can't understand the error.

    What does it mean?

    Thanks for your support.

    miller

  • I haven't encountered that kind of errormessage yet.

    BOL nor KB contain an exact ref.

    What happens if you execute that statement separately ?

    (is the error persistent ?)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 15 posts - 1 through 15 (of 16 total)

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