Re: Composite Keys

From: Jorge Godoy <jgodoy(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Composite Keys
Date: 2007-02-24 17:22:56
Message-ID: 200702241522.56438.jgodoy@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Em Sábado 24 Fevereiro 2007 03:28, RPK escreveu:
> First, can a primary key field be only one? I mean can I define a primary
> containing two fields.
>
> I have a table called "Payments" where there are two fields, "ReceiptNo"
> and "PaymentDate". If I take "ReceiptNo" only as a primary key then chances
> are of "primary key violation". Because in some places the receipt books
> have numbers that start with 1. I mean Receipt Book 1 nos. 1-100. Receipt
> Book 2 nos. 1-100, and so on.
>
> So I want to take ReceiptNo and PaymentDate as primary key field. Is it
> possible to define composite key in PGSQL. Please also suggest if any other
> approach would be fine.

It is possible, but it looks like you'd really want ReceiptBookNo + ReceiptNo
as a primary key...

If you use that you can then control the number of left recipes on each
receipt book or when to order new books.

If you use the date take special care with long term payments so that you
don't have two recipes "10" scheduled for the same day.

--
Jorge Godoy <jgodoy(at)gmail(dot)com>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-02-24 17:26:26 Re: perfromance world records
Previous Message Ron Johnson 2007-02-24 17:17:45 Re: perfromance world records