我的任务是将powershell脚本转换为python,除此之外,我已经完成了所有的工作。该脚本使用Microsoft.SqlServer.Management.Smo.Scripter类的URN对象创建droptable和createtable.sql。有没有办法在python中模仿这一点? 动力壳
$allTablesCollection = $mySQLSMOConnection.Databases[$Database].Tables
foreach ($table in $ExtractTables) {
$foundTable = $false
foreach ($allTable in $allTablesCollection) {
if ($table -eq $allTable.Name) {
[Array]$allUrns += $allTable.Urn
$tableHash = @{
"dbName" = $allTable.Parent
"schema" = $allTable.Schema
"tableName" = $allTable.Name
}
[Array]$allTables += $tableHash
$foundTable = $true
}
}
$dropscript = new-object("Microsoft.SqlServer.Management.Smo.Scripter")
$dropscript.Server=$mySQLSMOConnection
$dropscript.Options.ScriptDrops = $True
$dropscript.Options.IncludeIfNotExists = $True
$dropscript.Options.FileName = "$bcpOutputDir\schema\DropTables.sql"
$dropscript.Options.AppendToFile = $True
$createscript = new-object("Microsoft.SqlServer.Management.Smo.Scripter")
$createscript.Server=$mySQLSMOConnection
$createscript.Options.NoIdentities = $True
$createscript.Options.ScriptDrops = $False
$createscript.Options.NoFileGroup = $true
$createscript.Options.IncludeIfNotExists = $False
$createscript.Options.FileName = "$bcpOutputDir\schema\CreateTables.sql"
$createscript.Options.AppendToFile = $True
$dropscript.Script($allUrns) + "GO `r" | Out-String
$createscript.Script($allUrns) + "GO `r" | Out-String
目前没有回答
相关问题 更多 >
编程相关推荐