RPK wrote:
> First, can a primary key field be only one? I mean can I define a primary
> containing two fields. 

As many as you like :)

> 
> 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.

CREATE TABLE payments (receiptno serial, paymentdate date, primary key
(reciptno,paymentdate))

Sincerely,

Joshua D. Drake

-- 

      === The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive  PostgreSQL solutions since 1997
             http://www.commandprompt.com/

Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to