SET NOCOUNT ON GO DECLARE @object_name SYSNAME DECLARE @cmdstr NVARCHAR(300) DECLARE @servername SYSNAME DECLARE @instancename SYSNAME DECLARE @inputfile NVARCHAR(128) DECLARE @outputfile NVARCHAR(128) DECLARE @prodsrvs TABLE(srvname sysname) DECLARE crs_srv CURSOR LOCAL FAST_FORWARD READ_ONLY FOR SELECT srvname FROM @prodsrvs INSERT INTO @prodsrvs(srvname) SELECT 'Server-01' UNION ALL SELECT 'Server-02' UNION ALL SELECT 'Server-03' UNION ALL SELECT 'Server-04' OPEN crs_srv FETCH NEXT FROM crs_srv INTO @servername WHILE @@FETCH_STATUS=0 BEGIN SELECT @cmdstr = 'sqlcmd -S ' + @servername + ' -i "\\PathToScript\Script.sql" -o "\\PathToScript\script_output.txt" ' EXEC dbo.xp_cmdshell @cmdstr PRINT(@servername) WAITFOR DELAY '00:00:05' FETCH NEXT FROM crs_srv INTO @servername END CLOSE crs_srv DEALLOCATE crs_srv SET NOCOUNT OFF GO
This blog contains information related to Microsoft SQL Server and Oracle Administration: Installation, Configuration, Maintenance and Troubleshooting.
7/19/2012
Script deployment to multiple servers
I use the following script in order to deploy a T-SQL script to multiple servers:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment