Skip site navigation (1) Skip section navigation (2)

Re: Setting unique constraints.

From: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>
To: "'Anil Jangam'" <anilj(at)indts(dot)com>, pgsql-cygwin(at)postgresql(dot)org
Subject: Re: Setting unique constraints.
Date: 2001-12-18 08:57:49
Message-ID: FED2B709E3270E4B903EB0175A49BCB1047383@dogbert.vale-housing.co.uk (view raw or flat)
Thread:
Lists: pgsql-cygwin

> -----Original Message-----
> From: Anil Jangam [mailto:anilj(at)indts(dot)com] 
> Sent: 18 December 2001 06:13
> To: 'Dave Page'; pgsql-cygwin(at)postgresql(dot)org
> Subject: Setting unique constraints.
> Importance: High
> 
> 
> Hi,
> 
> Is there any way to apply the unique constraint on the 
> attribute of a table through the pgAdmin?. This certainly 
> other than applying the primary key constraint on the attribute.

Yes, assuming your data is already unique, you can just create a unique
index on the column(s) required. This is how PostgreSQL enforces unique
constraints when you added them with CREATE TABLE.

> To set the foreign key relationship it is the basic 
> requirement that the referenced attribute should be a primary 
> key in the referenced table.

I'm not sure this is the case.

> Can I achieve FK relationship without making it a primary 
> key?? Because I have already defined a PK, which does not 
> contain the referenced attribute. If it is possible to have a 
> unique attribute rather having PK and then achieve the FK.

I don't think you need to define a primary key or unique constraint. Just
add the foreign key when you define the table - if PostgreSQL doesn't like
it it will certainly tell you about it.

Regards Dave.

pgsql-cygwin by date

Next:From: Dave PageDate: 2001-12-18 09:24:07
Subject: Re: Resue of the sql dump to create new database.
Previous:From: Anil JangamDate: 2001-12-18 06:13:22
Subject: Setting unique constraints.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group