【问题标题】:Create a dummy value创建一个虚拟值
【发布时间】:2020-05-04 16:56:42
【问题描述】:

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

Product table example

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

【问题讨论】:

    标签: sql sql-server ssis etl


    【解决方案1】:

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

    set identity_insert products off;
    
    insert into products (productId, . . .)
        values (-1, . . . )
    
    set identity_insert products on;
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-12
      • 2020-09-03
      • 1970-01-01
      • 2020-01-11
      • 2021-11-27
      • 2014-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多