/java/

PostgreSQL add UNIQUE

2015-10-18 13:13:42

If one of our column have to be UNIQUE, like username in user table:

CREATE TABLE btbw.users (
  id serial PRIMARY KEY NOT NULL,
  username VARCHAR(32) NOT NULL,
  password VARCHAR(64) NOT NULL
);

We can do this by:

ALTER TABLE btbw.users ADD CONSTRAINT username_uniquer UNIQUE (username);