使用Azure Powershell执行.sql文件

前端之家收集整理的这篇文章主要介绍了使用Azure Powershell执行.sql文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经看过从Azure Power shell运行sql命令的示例,例如
$connectionString = "Data Source=MyDataSource;Initial Catalog=MyDB;User ID=user1;Password=pass1;Connection Timeout=90"
$connection = New-Object -TypeName System.Data.sqlClient.sqlConnection($connectionString)
$query = "CREATE TABLE...." 
$command = New-Object -TypeName System.Data.sqlClient.sqlCommand($query,$connection)
$connection.Open()
$command.ExecuteNonQuery()
$connection.Close()

有没有办法用引用包含整个sql脚本的外部文件替换$query?

谢谢.

解决方法

搜索20分钟,我发现了它.
$connectionString = "Data Source=MyDataSource;Initial Catalog=MyDB;User ID=user1;Password=pass1;Connection Timeout=90"
$connection = New-Object -TypeName System.Data.sqlClient.sqlConnection($connectionString)
$query = [IO.File]::ReadAllText("C:\...\Testsql.sql")
$command = New-Object -TypeName System.Data.sqlClient.sqlCommand($query,$connection)
$connection.Open()
$command.ExecuteNonQuery()
$connection.Close()
原文链接:https://www.f2er.com/mssql/74947.html

猜你在找的MsSQL相关文章