Re: Composite Keys - Mailing list pgsql-general

From Jorge Godoy
Subject Re: Composite Keys
Date
Msg-id 200702241522.56438.jgodoy@gmail.com
Whole thread Raw
In response to Composite Keys  (RPK <rohitprakash123@indiatimes.com>)
Responses Re: Composite Keys  (RPK <rohitprakash123@indiatimes.com>)
List 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@gmail.com>


pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: perfromance world records
Next
From: "Joshua D. Drake"
Date:
Subject: Re: perfromance world records