I have a table in PostgreSQL where the schema looks like this:
CREATE TABLE "foo_table" (
"id" serial NOT NULL PRIMARY KEY,
"permalink" varchar(200) NOT NULL,
"text" varchar(512) NOT NULL,
"timestamp" timestamp with time zone NOT NULL
)
Now I want to make the permalink unique across the table by ALTER-ing the table. Can anybody help me with this?
TIA
This question is related to
sql
postgresql
unique-constraint
it's also possible to create a unique constraint of more than 1 column:
ALTER TABLE the_table
ADD CONSTRAINT constraint_name UNIQUE (column1, column2);
Or, have the DB automatically assign a constraint name using:
ALTER TABLE foo ADD UNIQUE (thecolumn);
it's also possible to create a unique constraint of more than 1 column:
ALTER TABLE the_table
ADD CONSTRAINT constraint_name UNIQUE (column1, column2);
Or, have the DB automatically assign a constraint name using:
ALTER TABLE foo ADD UNIQUE (thecolumn);
Source: Stackoverflow.com