According to PostgreSQL documentation a table can have at most one primary key (while it can have many unique and not-null constraints).
CREATE TABLE products (
product_no integer PRIMARY KEY,
name text,
price numeric
);
So what happens when you make two columns the primary keys like in the table below?
CREATE TABLE example (
a integer,
b integer,
c integer,
PRIMARY KEY (a, c)
);
Is the "main" primary key "a" or is just a unique/not null constraint set for a and c? How does postgresql know which one is the main primary key?
Any help would be great. Thanks
Also what would the following produce? Would the primary key still be the commination of a and c or would a be the primary key and c would just be a constraint that is unique/not null?
CREATE TABLE example (
a integer PRIMARY KEY,
b integer,
c integer,
PRIMARY KEY (c)
);
After testing the above produces:
ERROR: multiple primary keys for table "example" are not allowed
LINE 5: PRIMARY KEY (c)
And yet a third case which may be the same as the one above:
CREATE TABLE example (
a integer PRIMARY KEY,
b integer,
c integer PRIMARY KEY
);
After testing the above produces:
ERROR: multiple primary keys for table "example" are not allowed
LINE 4: c integer PRIMARY KEY