September 2, 2011 at 1:59 pm
Is there a way to run .sql files from the SSMS query window thru a command, similar to the Oracle '@' sign operator?
I've researched using Powershell for this. I can certainly right click an object, open Powershell then use a cumbersome command to run the script, but I might as well just open the .sql file thru SSMS and 'Execute'.
I thought that I could run something like:
PS1: <cmd>
from the query window but cannot find any reference to this now.
Ultimately, I'd like to run some pre-developed queries that I've placed in .sql files, such as the following (overly simplified) example without leaving the command line:
select name from sys.databases
EDIT: Title should read "Run .sql files from SSMS"
----------------------------------------------------------------------------
Sacramento SQL Server users group - http://sac.sqlpass.org
Follow me on Twitter - @SQLDCH
----------------------------------------------------------------------------
September 3, 2011 at 8:56 am
You can turn on SQLCMD mode which will allow you to use SQLCMD syntax. The one I think you are looking for is:
:r filename
That will load the SQLCMD code in the filename and once a batch terminator is found, execute the code.
More information on this is available in Books Online under the topic SQLCMD Mode.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply