我是 postgres 的新手,一直在尝试找到一种方法来对字段设置最大限制。我的数据库中有一个名为 friends 的字段,其类型为 INT 我想对该字段施加 30 的约束,以便该字段中保存的数字不能被高于 30。我正在使用 postgres 9.4 和 PgAdmin 3 。我正在阅读此页http://www.postgresql.org/docs/9.4/static/sql-set-constraints.html但找不到任何东西。
最佳答案
为此使用 CHECK
约束。
创建架构时,只需键入:
CREATE TABLE sometable (
...
friends int CONSTRAINT high_friends CHECK (friends <= 30)
)
关于postgresql - Postgres 9.4 如何对 int 字段进行最大约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075100/