Search Postgresql Archives

Re: Composite Keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux