Unique Constraints

When the UNIQUE constraint is applied, every time you add a new row it checks if the value is already in the table. If the value exists in the column, it rejects the change and returns an error. The same process is performed for updating existing data.

CREATE TABLE table_name (
c1 data_type,
c2 data_type,
c3 data_type,
UNIQUE (c2, c3) );

Example:

CREATE TABLE ekipmanlar (id SERIAL PRIMARY KEY, name VARCHAR
(50) NOT NULL, ekipman_id VARCHAR (16) NOT NUL) );

CREATE UNIQUE INDEX CONCURRENTLY ekipman_ekip_id ON ekipmanlar
(ekipman_id);

ALTER TABLE ekipmanlar ADD CONSTRAINT unique_ekipman_id UNIQUE
USING INDEX ekipman_ekip_id;

The command adds a unique constraint to the ekipmanlar table using the ekipman_ekip_id index.