简体   繁体   中英

Run .sql file in sql server management studio

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

Other than SQLCMD or OSQL ; you can use SSMS if you have it installed. Double click on the *.sql file and it will open in SSMS -> connect to the DB server instance -> click on run in SSMS.

SSMS is the wrong tool to run 'files'. Is not an automation tool. Use sqlcmd or PowerShell for automation.

Now strict to your question: SSMS can run queries in SQLCMD mode , in which the :r command is available:

:r FileName
Parses additional Transact-SQL statements and SQLCMD commands from the file specified by FileName into the statement cache. FileName is read relative to the startup directory for Visual Studio. The file is read and executed after a batch terminator is encountered. You can issue multiple :r commands. The file can include any SQLCMD command, including the batch terminator that is defined in Tools, Options. You can use :r in a pre-deployment or post-deployment script to include other scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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