Re: Unique index VS unique constraint

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Unique index VS unique constraint
Дата
Msg-id 524F1BBE.2070708@gmail.com
обсуждение исходный текст
Ответ на Re: Unique index VS unique constraint  ("lucazeo@gmail.com" <lucazeo@gmail.com>)
Список pgsql-sql
On 10/04/2013 10:41 AM, lucazeo@gmail.com wrote:
> Il 04/10/2013 18:48, JORGE MALDONADO ha scritto:
>> I have search for information about the difference between "unique
>> index" and "unique constraint" in PostgreSQL without getting to a
>> specific answer, so I kindly ask for an explanation that helps me
>> clarify such concept.
>
> 2 main differences.
>
> First is the meaning: primary key identifies a record. A unique just
> tells you that that value of the record, in the table is unique. If you
> use keys, db structure will be more intelligible (my opinion).

Not sure I follow, you can have a unique index that is not a primary 
key. A primary key is special kind of unique index:

http://www.postgresql.org/docs/9.3/interactive/sql-createtable.html

The primary key constraint specifies that a column or columns of a table 
can contain only unique (non-duplicate), nonnull values. Technically, 
PRIMARY KEY is merely a combination of UNIQUE and NOT NULL, but 
identifying a set of columns as primary key also provides metadata about 
the design of the schema, as a primary key implies that other tables can 
rely on this set of columns as a unique identifier for rows.


>
> Second one is functional: in an unique constraint you can allow NULL
> values and ignore them. A primary key does not allow this.
>
>> Respectfully,
>> Jorge Maldonado
>
> Regards,
>
> Luca.
>
>


-- 
Adrian Klaver
adrian.klaver@gmail.com



В списке pgsql-sql по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Unique index VS unique constraint
Следующее
От: JORGE MALDONADO
Дата:
Сообщение: Advice on defining indexes