gpt4 book ai didi

sql-server - sqlpackage表列表

转载 作者:行者123 更新时间:2023-12-05 03:05:08 25 4
gpt4 key购买 nike

我正在尝试使用动态表列表从 powershell 运行 sqlpackage,但在将表列表放入 var 时出现错误。我需要将表列表放入一个 var 中,因为它将动态生成。

下面的代码工作得很好:

.\sqlpackage.exe `
/a:Export `
/scs:"Data Source=$($ServerName);Initial Catalog=$($SourceDbName);User ID=my_user;Password=my_password" `
/tf:$BacPacFileName `
/p:TableData=[dbo].[QRTZ_CALENDARS] /p:TableData=[dbo].[QRTZ_SCHEDULER_STATE]

但是,当我将表列表放入 var 时,它失败了:

$tableList = "/p:TableData=[dbo].[QRTZ_CALENDARS] /p:TableData=[dbo].[QRTZ_SCHEDULER_STATE]"

.\sqlpackage.exe `
/a:Export `
/scs:"Data Source=$($ServerName);Initial Catalog=$($SourceDbName);User ID=my_user;Password=my_password" `
/tf:$BacPacFileName `
$($tableList)

错误文本:

.\sqlpackage.exe : Argument 'TableData' has an invalid value:'[dbo].[QRTZ_CALENDARS] /p:TableData=[dbo].[QRTZ_SCHEDULER_STATE]'.Table to extract data from must be specified using the two-part tablename format: schema_name.table_identifier.At line:1 char:1+ .\sqlpackage.exe `+ ~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (Argument 'T...ble_identifier.:String) [], RemoteException    + FullyQualifiedErrorId : NativeCommandError  Incorrect syntax near /.

最佳答案

$tableList 的值作为单个参数 传递,而不是参数列表。你实际上想在这里做的是splatting :

$cs = "Data Source=${ServerName};Initial Catalog=${SourceDbName};" +
'User ID=my_user;Password=my_password'

$params = '/a:Export',
"/scs:`"${cs}`"",
"/tf:${BacPacFileName}",
'/p:TableData=[dbo].[QRTZ_CALENDARS]',
'/p:TableData=[dbo].[QRTZ_SCHEDULER_STATE]'

.\sqlpackage.exe @params

关于sql-server - sqlpackage表列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51333406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com