【问题标题】:Netezza foreign key constraintNetezza 外键约束
【发布时间】:2023-03-24 21:49:01
【问题描述】:

虽然 Netezza 有外键的概念,但为什么不“强制”外键约束?不强制执行约束有什么好处?

【问题讨论】:

    标签: netezza


    【解决方案1】:

    Foreign Keys 仍被查询优化器用于帮助构建最有效的查询计划,同时估计查询成本。使用Foreign / Primary Keys 来利用包括Microsoft Visio 在内的许多数据库可视化工具也很重要。不强制执行约束的好处是速度。 Netezza 能够通过不维护此功能来挤压额外的性能。

    Netezza Manual

    【讨论】:

      【解决方案2】:

      测试 Netezza SQL:FOREIGN KEY 子句

      ------------------------------------------------------------------
      /*
      NOTICE:  foreign key constraints not enforced       <-- Netezza SQL Parser complains here
       */
      /* Start time 4/25/2013 6:21:32 PM, end time 4/25/2013 6:21:32 PM. */
      /* Duration 0.078125 sec. */
      CREATE TABLE table2ref
      (
              col1    smallint NOT NULL
             ,colref2 smallint
             ,col3      varchar(30 )
        ,CONSTRAINT fk_column_colref2                                      <-- THIS IS REF CONSTRAINT
         FOREIGN KEY (colref2) 
         REFERENCES test2delete (col1)                     <-- the ref table must already be created 
      );
      
      /* Start time 4/25/2013 6:21:32 PM, end time 4/25/2013 6:21:37 PM. */
      /* Duration 4.53125 sec. */                         <-- Observe how long the INSERT takes
      /* Records Affected: 1. */
      
      insert into table2ref values (3,12345,'reftabstring'); <-- THIS IS NON-EXISTING KEY "12345"
      
      /* Start time 4/25/2013 6:21:37 PM, end time 4/25/2013 6:21:39 PM. */
      /* Duration 2.65625 sec. */                         <-- Observe how long the INSERT takes
      /* Records Affected: 1. */
      
      insert into table2ref values (3,12345,'reftabstring');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-17
        • 2017-04-20
        • 2018-03-05
        • 2013-01-30
        • 2014-01-16
        • 1970-01-01
        相关资源
        最近更新 更多