【问题标题】:How can I write a power shell code to call a .sql file?如何编写 powershell 代码来调用 .sql 文件?
【发布时间】:2015-10-22 00:21:21
【问题描述】:

我有几个 .sql 脚本。我想编写一个包装函数/脚本来调用和运行所有这些 .sql 文件。它可以在 sql 或 powershell 中。

感谢您的帮助。

【问题讨论】:

  • either SQL or Powershell 是什么意思?如果要在 SQL 中运行,可以将所有脚本(.sql)添加到存储过程中。
  • 我的意思是我需要用 sql 或 powershell 写一个脚本。
  • 谢谢。那么我的商店过程中的示例代码是什么?

标签: sql sql-server powershell powershell-2.0


【解决方案1】:
Get-ChildItem -Path "path_to_folder_with_scripts" -Filter "*.sql" | % {invoke-sqlcmd -InputFile $_.FullName}

编辑 path_to_folder_with_scripts 到您的带有 sql 文件的文件夹的路径

【讨论】:

  • 这仅显示文件夹中的 sql 文件。我需要运行它们。
  • @kimitrio:这就是调用 sqlcmd 的管道所做的。
猜你喜欢
  • 1970-01-01
  • 2011-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多