Re: Unique index and unique constraint

From: Luca Vernini <lucazeo(at)gmail(dot)com>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Unique index and unique constraint
Date: 2013-07-26 22:07:43
Message-ID: CAHZ=uVBDq1hx5ZJFfY40Y7BnXQMqze2=e8dWuRwEjL+qB20q_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)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
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alvaro Herrera 2013-07-26 22:19:37 Re: Unique index and unique constraint
Previous Message JORGE MALDONADO 2013-07-26 21:44:05 Unique index and unique constraint