Re: how to create secondary key!!

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: "Nelson Yong" <nelsonyong(at)ipmuda(dot)com(dot)my>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: how to create secondary key!!
Date: 2002-10-24 04:41:57
Message-ID: web-1797585@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Nelson,

> What i call the Secondary key is when i want two or more fields
> become
> key eg. Order Table can be more than one or more transaction, i
> assign
> order no. and record no. as key. The Order no. call primary key and
> the
> Record no. as secondary key.

I'm afraid that's incorrect. What you have is a "two-column primary
key." There is no "secondary key". Here's how you create one:

create table order_detail (
order_no INT NOT NULL REFERENCES orders(order_no),
record_no INT NOT NULL,
item_no INT NOT NULL REFERENCES inventory(item_no),
quantity NUMERIC NOT NULL,
comment TEXT,
CONSTRAINT order_detail_PK PRIMARY KEY (order_no, record_no)
);

Got it? Read the "CREATE TABLE" documentation for more detail.

-Josh Berkus

P.S. To reiterate: There are Primary Keys, Candidate Keys, Surrogate
Keys, and Foreign Keys, but no "Secondary Keys".

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message cristi 2002-10-24 05:03:13 display functions
Previous Message Josh Berkus 2002-10-24 00:07:50 Re: [BUGS] Optimization disaster