根据PostgreSQL文档,一个表最多只能有一个主键(虽然它可以有许多唯一和非空约束) .
CREATE TABLE products (
product_no integer PRIMARY KEY,
name text,
price numeric
);
那么当你将两列作为主键时会发生什么呢?
CREATE TABLE example (
a integer,
b integer,
c integer,
PRIMARY KEY (a, c)
);
“主”主键是“a”还是只是为a和c设置的唯一/非空约束? postgresql如何知道哪一个是主键?
任何帮助都会很棒 . 谢谢
以下会产生什么?主键是否仍然是a和c的组合,或者是主键,而c只是一个唯一/非空的约束?
CREATE TABLE example (
a integer PRIMARY KEY,
b integer,
c integer,
PRIMARY KEY (c)
);
经过测试,以上产品:
ERROR: multiple primary keys for table "example" are not allowed
LINE 5: PRIMARY KEY (c)
而第三种情况可能与上述情况相同:
CREATE TABLE example (
a integer PRIMARY KEY,
b integer,
c integer PRIMARY KEY
);
经过测试,以上产品:
ERROR: multiple primary keys for table "example" are not allowed
LINE 4: c integer PRIMARY KEY