Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 run query against each machine

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-04-29 : 05:20:56
Hi,
There is a table called tableName in a sql server called ServerName
This table has the name of several sql server machines in a field called FieldName.

How do I execute a t-sql query against each of these sql servers?
I can run a cursor to get this name one by one and then run the following query against each sql server.

use master
ALTER DATABASE [model] MODIFY FILE ( NAME = N'modellog', SIZE = 1000KB )

I am not sure where to use the machine name so that the query runs against that particular sql server machine.

Any thoughts please?
Thanks

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-04-29 : 08:39:33
www.sommarskog.se/dynamic_sql.html

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

whitefang
Enterprise-Level Plonker Who's Not Wrong

272 Posts

Posted - 2009-04-29 : 08:40:30
Add a linked server
http://blogs.techrepublic.com.com/datacenter/?p=133
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-04-29 : 09:11:42
quote:
Originally posted by whitefang

Add a linked server
http://blogs.techrepublic.com.com/datacenter/?p=133


I do not think adding linked server is a good idea, remember there are many sql server machines to run the query against.
Thanks
Go to Top of Page
   

- Advertisement -