PostgreSQL Alter table add unique key constraint to a table

Add unique key constraint to table

How to add unique key constraint to an existing table. Constraint syntax and example.

Syntax

ALTER TABLE table_name 
ADD CONSTRAINT key_name 
UNIQUE (column_name);

Example

ALTER TABLE users 
ADD CONSTRAINT uk_mail 
UNIQUE (usermail);