In Postgresql, force unique on combination of two columns
CREATE TABLE someTable ( id serial PRIMARY KEY, col1 int NOT NULL, col2 int NOT NULL, UNIQUE (col1, col2))
autoincrement
is not postgresql. You want a serial
.
If col1
and col2
make a unique and can't be null then they make a good primary key:
CREATE TABLE someTable ( col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY (col1, col2))
Create unique constraint that two numbers together CANNOT together be repeated:
ALTER TABLE someTableADD UNIQUE (col1, col2)
Seems like regular UNIQUE CONSTRAINT :)
CREATE TABLE example (a integer,b integer,c integer,UNIQUE (a, c));
More here