首页 > 解决方案 > 创建一个虚拟值

问题描述

我正在 SSIS 和 SQL Server 中创建数据仓库。现在为了处理迟到的尺寸,我想用代理键 -999 创建一个虚拟值。让我们以我的Products表为例,我已经拥有了ProductID,而Product_pkwhich 是我的代理键。

产品表示例

代理键是自动生成的。有没有办法用特定的代理键插入一个虚拟值?

标签: sqlsql-serverssisetl

解决方案


您可以通过在会话中设置参数来插入标识值,identity_insert.

set identity_insert products off;

insert into products (productId, . . .)
    values (-1, . . . )

set identity_insert products on;

请注意,会话中只能identity_insert关闭一个表。所以,你应该在完成后重新打开它。


推荐阅读