SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Select,Update,Delete,Insert etc.. in many server using 1 query

By Lester Policarpio, 2008/02/19

Total article views: 1109 | Views in the last 30 days: 69

What if your boss wants you to insert or updated a record in a table in several servers? lets say 50 server what would you do? Open each and every servers and run the insert or update? that will take time if you have several servers. Let this script do the job for you..... All you have to do is to linked that server to the server where you will run the script,create this procedure, run this script and whalaaaaa done....

NOTE: for you to use this script first modify the query by changing single quotes with double quotes

If your query is

select name from master..sysdatabases where name = 'master'

when applying it to the script it must be

select name form master..sysdatabase where name = ''master''

 

example query :

syntax usp_linked_query 'db_name','db_owner','query'

operation: usp_linked_query 'master','dbo','select name from sysdatabases where name = ''master'''

 

update example

 

usp_linked_query 'db_name','db_owner','update table_name set col_name = ''value'' where condition'

 

*Always change single quotes to double quotes and enclose the whole query with ' '

By Lester Policarpio, 2008/02/19

Total article views: 1109 | Views in the last 30 days: 69
Your response
 
 
Related tags

Linked Server    
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com