gpt4 book ai didi

postgresql - 外键可以用 `check` 表示吗?

转载 作者:行者123 更新时间:2023-11-29 14:31:26 25 4
gpt4 key购买 nike

来自postgresql manual

A check constraint is the most generic constraint type.

check 有多通用?外键可以用check表示吗?谢谢。

最佳答案

CREATE TABLE documentation包括 CHECK 约束的更多技术定义,包括这句话:

Currently, CHECK expressions cannot contain subqueries nor refer to variables other than columns of the current row.

CHECK 约束是通用的,因为您可以编写任意表达式,而不仅仅是列名或标准条件。 NOT NULL约束可以表示为 CHECK约束,可以限制 text 的长度/VarChar列(即 foo VarChar(10) 大致相当于 foo text CHECK (length(foo) <= 10) )。

但是,约束始终是关于表的单行的断言。其他类型的约束用于其他类型的断言:

  • 为了断言表中行之间的比较,有UNIQUE , PRIMARY KEY , 和 EXCLUSION限制条件。
  • 为了断言不同表中行之间的关系,或表中行之间的自引用,有FOREIGN KEY限制条件。

关于postgresql - 外键可以用 `check` 表示吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51249103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com