开发者

Way of executing several .sql files at once in SQL Server

I have around 100 .sql files that create stored procs. I'd like to execute them at once all of them.

They are contained inside a folder called Stor开发者_高级运维ed Procedures. There several other folders with different names --Table names-- inside the Stored Procedures folder.

Is there a way to execute all these files at once?


You could open up a PowerShell instance and run a command like the following:

Get-ChildItem ".\Stored Procedures\*.sql" | ForEach-Object { sqlcmd -S ServerName -d DatabaseName -E -i $_.FullName }

This will get each .sql file in the Stored Procedures directory, and one by one, pass it to the sqlcmd.exe program. To get more details on the parameters for sqlcmd you can run sqlcmd /?.

To make it recursive through sub directories, you can apply the -Recurse parameter to Get-ChildItem along with the -Filter parameter:

Get-ChildItem '.\Stored Procedures' -Filter *.sql -Recurse | ForEach-Object { sqlcmd -S ServerName -d DatabaseName -E -i $_.FullName }


Here is the another tool Sql_Server_Script_Executor

Is there a way to execute all these files at once?

*You can add folder and all your files will comes up in the list. Click the execute button and done!!!!!!!!!!!!! *

It contains three transaction modes.

1. Execute scripts within one transaction
2. Execute scripts on separate transaction
3. No transaction

and many more features please go through it.

Way of executing several .sql files at once in SQL Server


Not at once - but all in one go - try a tool like the SSW Deploy one.

Way of executing several .sql files at once in SQL Server

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜