【问题标题】:Constraints in other schema其他模式中的约束
【发布时间】:2018-05-01 10:12:29
【问题描述】:

在试验information_schema.* 视图时,我了解到可以在另一个模式中定义约束。这反映在information_schema.table_constraints 视图中,它添加了诸如constaint_schema 之类的列来表示这一点:

select * from information_schema.table_constraints

constraint_catalog | constraint_schema | constraint_name | table_catalog | table_schema | table_name | constraint_type | is_deferrable | initially_deferred 

对于外键,这是有道理的:可以引用另一个模式中的表。

我现在想知道这是否也适用于其他约束。也就是说,是否有可能在另一个模式中将主约束、唯一约束或检查约束定义为定义表的模式? 在哪些情况下constraint_schemainformation_schema.table_constraints 中的table_schema 不同?

【问题讨论】:

    标签: postgresql constraints information-schema


    【解决方案1】:

    https://www.postgresql.org/docs/current/static/sql-createindex.html

    索引始终在与其父表相同的架构中创建

    https://www.postgresql.org/docs/current/static/ddl-constraints.html

    添加唯一约束会自动创建唯一的 B-tree 约束中列出的列或列组的索引。

    添加主键会自动创建唯一的 B-tree 索引 在主键中列出的列或列组上

    因此 pk 或 unique 肯定会与同一架构中的表一起旅行。关于 check 而不是 null - 我想不出任何方式来争论为什么它们不能在不同的模式中,但要么我看不出它们如何出现在不同的模式中......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-29
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      相关资源
      最近更新 更多