How to run multiple SQL scripts, in SSMS, against SQL Azure? -
i execute multiple sql (*.sql) tsql script files, in ssms, against sql azure db. happen using ssms 2008 r2
the code, tried execute in ssms query window, linked relevant db instance, picked previous question, :
/* execute list of .sql files against server , db specified */ set nocount on set xact_abort on begin tran declare @dbservername varchar(100) = 'dbservername ' declare @dbname varchar(100) = 'dbname' declare @filepath varchar(200) = 'c:\temp\scripts' /* create holder filenames executed */ declare @filelist table (files nvarchar(max)) insert @filelist values ('script1.sql') insert @filelist values ('script2.sql') insert @filelist values ('script3.sql') while (select count(files) @filelist) > 0 begin /* execute each file 1 @ time */ declare @filename nvarchar(max) = (select top(1) files @filelist) declare @command varchar(500) = 'sqlcmd -s ' + @dbservername + ' -d ' + @dbname + ' -i "' + @filepath + @filename +'"' exec xp_cmdshell @command print 'executed: ' + @filename delete @filelist files = @filename end commit tran
unfortunately sql azure not support "xp_cmdshell".
how can execute multiple sql scripts azure sql instance?
thanks in advance.
p.s aware of how 1 can open file in ssms
when using ssms script send server , executed there. mentioned in comment in sql database server not have access files on machines hosted on nor can upload them these machines. approach not work. opening files have locally on machine not possible.
to execute set of scripts local machine against sql database have translate sql script example powershell script:
get-childitem "c:\temp\scripts" -filter script*.sql | ` foreach-object{ write-host 'executing' $_.fullname sqlcmd -u <username>@<server> -p <password> -s <server>.database.windows.net -d <databasename> -i $_.fullname }
Comments
Post a Comment