Re: Unique index VS unique constraint

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: David Johnston <polobo(at)yahoo(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Unique index VS unique constraint
Date: 2013-10-06 00:59:28
Message-ID: CAL_0b1uAZLLLipu0_RhcqrsAE1WkBJVYHHOfHuP1VcZVMzKAtg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Oct 5, 2013 at 3:24 PM, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> wrote:
> So, let´s say that I have the following simple example table:
>
> 1. cus_id
> 2. cus_name
> 3. Other fields . . .
>
> Where "cus_id" is the primary key. And let´s also say that I want "cus_name"
> to be unique. I have the option to create a unique constraint or a unique
> index. What would be the best decision and why?

Unique constraint would be the right choice, because you want to
constrain the values in the column of your table. The unique index is
just a tool the constrain uses to perform its function. This index
will be created automatically when you add the constraint.

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Kaleeswaran Velu 2013-10-08 16:23:09
Previous Message JORGE MALDONADO 2013-10-05 22:24:26 Re: Unique index VS unique constraint