BCP 文件插入命令未恢复标识列的实际值

BCP file insert command is not restoring the actual value of the Identity column

BCP 插入脚本不恢复复制到 BCP 文件中的身份列值,而是 SQL服务器根据恢复过程中指定的种子和增量值自动分配唯一值。

创建BCP格式文件-

BCP [SourceDatabase].[abc].[TableName] format nul -T -c -f Filename.fmt -S SourceSqlServer

创建 BCP 数据文件 -

BCP "EXEC [abc].[GetData]" queryout "C:\Filename.bcp" -S SourceSqlServer -d SourceDatabase -T **-E** -c

恢复数据进入table-

BCP [abc].[TableName] in "C:\Filename.bcp" -f Filename.fmt -S SourceSqlServer -d SourceDatabase -T

我想插入与 BCP 文件中相同的标识列的值。任何建议表示赞赏。

默认情况下,您需要添加 -E 开关 bcp 分配新的标识列。

https://docs.microsoft.com/sr-latn-rs/sql/relational-databases/import-export/keep-identity-values-when-bulk-importing-data-sql-server?view=sql-server-2014