在目录中运行所有SQL文件 [英] Run all SQL files in a directory

查看:117
本文介绍了在目录中运行所有SQL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须运行多个.sql文件,以便将其他开发人员所做的更改应用于SQL Server 2005数据库. 这些文件是根据以下模式命名的:

I have a number of .sql files which I have to run in order to apply changes made by other developers on an SQL Server 2005 database. The files are named according to the following pattern:

0001 - abc.sql
0002 - abcef.sql
0003 - abc.sql
...

有没有一种方法可以一次运行所有这些?

Is there a way to run all of them in one go?

推荐答案

使用以下命令创建.BAT文件:

Create a .BAT file with the following command:

for %%G in (*.sql) do sqlcmd /S servername /d databaseName -E -i"%%G"
pause

如果您需要提供用户名和密码

If you need to provide username and passsword

for %%G in (*.sql) do sqlcmd /S servername /d databaseName -U username -P 
password -i"%%G"

请注意,提供用户名/密码时不需要"-E"

Note that the "-E" is not needed when user/password is provided

将此.BAT文件放置在您希望从中执行.SQL文件的目录中,双击.BAT文件即可!

Place this .BAT file in the directory from which you want the .SQL files to be executed, double click the .BAT file and you are done!

这篇关于在目录中运行所有SQL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆