Re: Unique index and unique constraint

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: Unique index and unique constraint
Дата
Msg-id 20130726221937.GL14652@eldon.alvh.no-ip.org
обсуждение исходный текст
Ответ на Unique index and unique constraint  (JORGE MALDONADO <jorgemal1960@gmail.com>)
Ответы Re: Unique index and unique constraint  (Sergey Konoplev <gray.ru@gmail.com>)
Re: Unique index and unique constraint  (Dmitriy Igrishin <dmitigr@gmail.com>)
Список pgsql-sql
JORGE MALDONADO escribió:
> 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.

The SQL standard does not mention indexes anywhere.  Therefore, in the
SQL standard world, the way to define uniqueness is by declaring an
unique constraint.  Using unique constraints instead of unique indexes
means your code stays more portable.  Unique constraints appear in
INFORMATION_SCHEMA.TABLE_CONSTRAINTS, whereas unique indexes do not.

PostgreSQL implements unique constraints by way of unique indexes (and
it's likely that all RDBMSs do likewise).  Also, the syntax to declare
unique indexes allows for more features than the unique constraints
syntax.  For example, you can have a unique index that covers only
portion of the table, based on a WHERE condition (a partial unique
index).  You can't do this with a constraint.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



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

Предыдущее
От: Luca Vernini
Дата:
Сообщение: Re: Unique index and unique constraint
Следующее
От: JORGE MALDONADO
Дата:
Сообщение: Criteria to define indexes