pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Anton Gavazuk <antongavazuk@gmail.com>
To: JORGE MALDONADO <jorgemal1960@gmail.com>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: Advice on key design
Date: Wed, 24 Jul 2013 10:16:45 +0200
Message-ID: <1583742764256639694@unknownmsgid> (raw)
In-Reply-To: <CAAY=A78aYZ3OUhqQTejD1=XDNsuMLLqufiBzOC-Ki4YGY-pXYw@mail.gmail.com>
References: <CAAY=A7_ZKoCRjP19oLRYfQeV1=Q=c-3cX+qDmPfZC8_o_B8msQ@mail.gmail.com>
	<3311319936507639588@unknownmsgid>
	<CAAY=A78aYZ3OUhqQTejD1=XDNsuMLLqufiBzOC-Ki4YGY-pXYw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

The reason is simple - as you need the artificial PK  lpp_id, then
everything else becomes an constraint

Thanks,
Anton

On Jul 24, 2013, at 0:28, JORGE MALDONADO <jorgemal1960@gmail.com> wrote:

>> In your case it would be lpp_id as PK, and
>> lpp_person_id,lpp_language_id as unique constraint
>>
>> Thanks,
>> Anton

Is there a reason to do it the way you suggest?

Regards,
Jorge Maldonado


On Tue, Jul 23, 2013 at 5:02 PM, Anton Gavazuk <antongavazuk@gmail.com>wrote:

> Hi Jorge,
>
> In your case it would be lpp_id as PK, and
> lpp_person_id,lpp_language_id as unique constraint
>
> Thanks,
> Anton
>
> On Jul 23, 2013, at 23:45, JORGE MALDONADO <jorgemal1960@gmail.com> wrote:
>
> > I have 2 tables, a parent (tbl_persons) and a child
> (tbl_languages_per_person) as follows (a language table is also involved):
> >
> > ------------------
> > tbl_persons
> > ------------------
> > * per_id
> > * per_name
> > * per_address
> >
> > --------------------------------------
> > tbl_languages_per_person
> > --------------------------------------
> > * lpp_person_id
> > * lpp_language_id
> > * lpp_id
> >
> > As you can see, there is an obvious key in the child table which is
> "lpp_person_id + lpp_language_id", but I also need the field "lpp_id" as a
> unique key which is a field that contains a consecutive number of type
> serial.
> >
> > My question is: what should I configure as the primary key,
> "lpp_person_id + lpp_language_id" or "lpp_id"?
> > Is the role of a primary key different from that of a unique index?
> >
> > With respect,
> > Jorge Maldonado
> >
> >
> >
> >
> >
> >
>

view thread (10+ messages)  latest in thread

Message-ID: <1583742764256639694@unknownmsgid>
Permalink:  ../1583742764256639694@unknownmsgid/
Also on:    postgresql.org/message-id/1583742764256639694@unknownmsgid

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: antongavazuk@gmail.com, jorgemal1960@gmail.com
  Subject: Re: Advice on key design
  In-Reply-To: <1583742764256639694@unknownmsgid>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox