Re: Unique index and unique constraint

Поиск
Список
Период
Сортировка
От Luca Vernini
Тема Re: Unique index and unique constraint
Дата
Msg-id CAHZ=uVBDq1hx5ZJFfY40Y7BnXQMqze2=e8dWuRwEjL+qB20q_Q@mail.gmail.com
обсуждение исходный текст
Ответ на Unique index and unique constraint  (JORGE MALDONADO <jorgemal1960@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: JORGE MALDONADO
Дата:
Сообщение: Unique index and unique constraint
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Unique index and unique constraint