约束

约束为存储在表中的数据定义完整性和一致性规则。Snowflake 提供对 ANSI SQL 标准中定义的约束的支持,以及一些与其他数据库(如 Oracle)兼容的扩展。

重要

  • For standard tables, Snowflake supports defining and maintaining constraints, but doesn't enforce them, except for NOT NULL and CHECK constraints, which are always enforced.

    Violations of constraints might cause unexpected downstream effects. If you decide to create a constraint that must be relied upon, ensure that your downstream processes can maintain data integrity. For more information, see 约束属性.

    提供标准表约束主要是为了数据建模目的和与其他数据库的兼容性,以及支持使用约束的客户端工具。例如,Tableau 支持使用约束来执行联接剔除(联接消除),这可以提高生成的查询和多维数据集刷新的性能。

  • 对于 混合表,Snowflake 同时支持和强制执行约束。主键约束是必需的,并在所有混合表上强制执行,其他约束在使用时也会被强制执行。

后续主题: