无法像 @{file.sql} oracle sqlplus 语法那样从 SQL Server 查询管理器执行 SQL 脚本?

发布于 2024-09-29 15:22:32 字数 366 浏览 0 评论 0原文

正如标题所示,在 oracle 中,您可以在 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

无需 file->open sql 脚本即可将其加载到 UI。

SQL Server 查询管理器中有类似的功能吗?我偶然发现了很多可以使用它的情况,但我无法找到一种方法来完成它。

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.

Is 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

怀里藏娇 2024-10-06 15:22:32

您并不是真正在这里比较类似的工具。

SQL Server 中与 SQL*Plus 等效的工具是 SQLCMD 实用程序

特别是,您会对 -i 开关感兴趣,因为它允许您提供 .sql 文件作为输入。

编辑:

为了回复您的评论,您可以考虑使用系统存储过程xp_cmdshell 在 T-SQL 批处理中启动提示表单,允许您使用 SQLCMD。在我看来,这不是最优雅的解决方案,但它应该可行。

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.

清晰传感 2024-10-06 15:22:32

如果使用较新版本的 SQL Server(2005 和 2008),请查看 SQLCMD 中的 :r 命令是否适合您:

:r
指定的文件中解析其他 Transact-SQL 语句和 sqlcmd 命令进入语句缓存。
如果文件包含后面没有 GO 的 Transact-SQL 语句,则必须在 :r 之后的行中输入 GO。

来自 sqlcmd 实用程序

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

夏见 2024-10-06 15:22:32

使用 isql 实用程序 http://msdn.microsoft.com/en -us/library/aa214007(SQL.80).aspx

issql ... -iinputfile

眼眸 2024-10-06 15:22:32

还有 SQLS*Plus 工具,可用于在脚本中执行脚本

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文