I have a number of generated .sql files that I want to run in succession. I'd like to run them from a SQL statement in a query (i.e. Query Analyzer/Server Management Studio).
Is it possible to do something like this and if so what is the syntax for doing this?
I'm hoping for something like:
exec 'c:\temp\file01.sql' exec 'c:\temp\file02.sql'
I am using SQL Server 2005 and running queries in management studio.
command: mysql> source file_name mysql> \. The statement shown outputs <info_to_display> . You can also invoke mysql with the --verbose option, which causes each statement to be displayed before the result that it produces. mysql ignores Unicode byte order mark (BOM) characters at the beginning of input files.
use the MySQL command line client: mysql -h hostname -u user database < path/to/test. sql. Install the MySQL GUI tools and open your SQL file, then execute it.
use xp_cmdshell and sqlcmd
EXEC xp_cmdshell 'sqlcmd -S ' + @DBServerName + ' -d ' + @DBName + ' -i ' + @FilePathName
Very helpful thanks, see also this link: Execute SQL Server scripts for a similar example. To turn xp_cmdshell
on and off see below:
On
SET NOCOUNT ON EXEC master.dbo.sp_configure 'show advanced options', 1 RECONFIGURE EXEC master.dbo.sp_configure 'xp_cmdshell', 1 RECONFIGURE
Off
EXEC master.dbo.sp_configure 'xp_cmdshell', 0 RECONFIGURE EXEC master.dbo.sp_configure 'show advanced options', 0 RECONFIGURE SET NOCOUNT OFF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With