/java/

PostgreSQL remove PRIMARY KEY (DROP CONSTRAINT)

2015-10-18 13:08:29

In the last post, we created user table:

CREATE TABLE btbw.users (
  username VARCHAR(32) NOT NULL PRIMARY KEY,
  password VARCHAR(64) NOT NULL
);
ALTER TABLE btbw.users OWNER TO btbw;

but now we have new requirement: "User table should content id of the user"

What we have to do:

We have to remove current primary key

ALTER TABLE btbw_mtime.users DROP CONSTRAINT "users_pkey";

and add new one by

ALTER TABLE btbw_mtime.users ADD COLUMN id serial PRIMARY KEY NOT NULL;