Re: Unique index and unique constraint - Mailing list pgsql-sql

From Luca Vernini
Subject Re: Unique index and unique constraint
Date
Msg-id CAHZ=uVBDq1hx5ZJFfY40Y7BnXQMqze2=e8dWuRwEjL+qB20q_Q@mail.gmail.com
Whole thread Raw
In response to Unique index and unique constraint  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List pgsql-sql
I try to explain my point of view, also in my not so good English:
A primary key is defined by dr. Codd in relational model.
The key is used to identify a record. In good practice, you must always define a primary key. Always.

The unique constraint will simply say: this value (or combination) should not be found more than one time on this column in this table.

So you can say: just a convention?

Consider this:
If you say unique, you can still accept multiple rows with the same NULL value. This is not true with primary key.

You can define multiple unique constraint on a table, but only a primary key. This, and the concept of primary key, can help someone else to read your database. To know in same cases, the logic of the data, and know what identifies a row. That is not simply the same as: not duplicate this value.

Luca.


2013/7/26 JORGE MALDONADO <jorgemal1960@gmail.com>
I guess I am understanding that it is possible to set a unique index or a unique constraint in a table, but I cannot fully understand the difference, even though I have Google some articles about it. I will very much appreciate any guidance.

Respectfully,
Jorge Maldonado

pgsql-sql by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Unique index and unique constraint
Next
From: Alvaro Herrera
Date:
Subject: Re: Unique index and unique constraint