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 2008 Forums
 Transact-SQL (2008)
 stored proc that does multiple inserts

Author  Topic 

pespes
Starting Member

6 Posts

Posted - 2011-10-12 : 07:02:08
Hello all,

I need help in writing a stored proc that will insert into multiple servers i.e.qa/uat/int/para servers

I would want to deploy new inserts on the dev serverand copy this change across all these qa/uat/int/para servers...all help is well appreciated

Regards

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-10-12 : 07:09:36
If you are inserting just a few rows then I would create statements like

exec ('insert mydb..mytbl (col1, col2) select ''asd'',2') at myserver

If you need to copy data from a table then

insert myserver.mydb.dbo.mytbl (col1, col2) select col1, col2 from tbl

In both cases you will need to wrap them in dynamic sql statements if the server is to be parameterised and also create the linked servers.

Another option is an openrowset command to execute without a linked server.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-12 : 08:10:03
you will be inserting to multiple servers using same sp? why is it so? so do you've linked servers setup to all other servers from server you're going to create sp? I didnt understand the need of doing all these

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -