简体   繁体   English

在SQL Server Management Studio中运行.sql文件

[英]Run .sql file in sql server management studio

除了使用sqlcmd或osql之外,有什么方法可以在硬盘上运行.sql文件。

Other than SQLCMD or OSQL ; SQLCMDOSQL ; you can use SSMS if you have it installed. 如果已安装SSMS则可以使用它。 Double click on the *.sql file and it will open in SSMS -> connect to the DB server instance -> click on run in SSMS. 双击*.sql文件,它将在SSMS中打开->连接到数据库服务器实例->单击在SSMS中运行。

SSMS is the wrong tool to run 'files'. SSMS是运行“文件”的错误工具。 Is not an automation tool. 不是自动化工具。 Use sqlcmd or PowerShell for automation. 使用sqlcmd或PowerShell进行自动化。

Now strict to your question: SSMS can run queries in SQLCMD mode , in which the :r command is available: 现在严格来说,您的问题是:SSMS可以在SQLCMD模式下运行查询,在该模式下:r命令可用:

:r FileName
Parses additional Transact-SQL statements and SQLCMD commands from the file specified by FileName into the statement cache. 将FileName指定的文件中的其他Transact-SQL语句和SQLCMD命令解析到语句缓存中。 FileName is read relative to the startup directory for Visual Studio. 相对于Visual Studio的启动目录读取FileName。 The file is read and executed after a batch terminator is encountered. 遇到批处理终止符后,将读取并执行该文件。 You can issue multiple :r commands. 您可以发出多个:r命令。 The file can include any SQLCMD command, including the batch terminator that is defined in Tools, Options. 该文件可以包括任何SQLCMD命令,包括在“工具”,“选项”中定义的批处理终止符。 You can use :r in a pre-deployment or post-deployment script to include other scripts. 您可以在部署前或部署后脚本中使用:r来包含其他脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM