开发者

No way to execute SQL script from SQL Server Query Manager like @{file.sql} oracle sqlplus syntax?

开发者 https://www.devze.com 2023-01-22 04:27 出处:网络
Like the title says, in oracle you can issue the following command in SQL*Plus: SQL> select something from anothertable; #sql

Like the title says, in oracle you can issue the following command in SQL*Plus:

SQL> select something from anothertable; #sql
SQL> @{/home/me/somescript.sql};         #load sql from file and execute it
SQL> do something else in script;        #other sql

Without having to file->open the sql script to load it to the UI.

开发者_如何学GoIs there an equivalent in SQL Server Query Manager? I've stumbled upon many situation where i could have used it but i couldn't be able to find a way to accomplish it.


You're not really comparing like for like Tools here.

The equivalent tool to SQL*Plus in SQL Server is the SQLCMD Utility.

In particular you will be interested in the -i switch as this allows you to provide a .sql file as input.

Edit:

In response to your comment, you could look to use the system stored procedure xp_cmdshell to launch a prompt form within a T-SQL batch that allows you to use SQLCMD. Not the most elegant solution in my opinion but it should work.


If using latter versions of SQL Server (2005 & 2008), see if the :r command in SQLCMD works for you:

:r <filename> Parses additional Transact-SQL statements and sqlcmd commands from the file specified by <filename> into the statement cache. If the file contains Transact-SQL statements that arenot followed by GO, you must enter GO on the line that follows :r. From sqlcmd Utility


Use isql utility http://msdn.microsoft.com/en-us/library/aa214007(SQL.80).aspx

issql ... -iinputfile


There is also SQLS*Plus tool that you can use to execute scripts within a script

0

精彩评论

暂无评论...
验证码 换一张
取 消