Re: how to create secondary key!! - Mailing list pgsql-novice

From Josh Berkus
Subject Re: how to create secondary key!!
Date
Msg-id web-1797585@davinci.ethosmedia.com
Whole thread Raw
In response to how to create secondary key!!  ("Nelson Yong" <nelsonyong@ipmuda.com.my>)
Responses Postgres and Sybase  ("Rob" <rob@jamwarehouse.com>)
List 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".



pgsql-novice by date:

Previous
From: Josh Berkus
Date:
Subject: Re: [BUGS] Optimization disaster
Next
From: "cristi"
Date:
Subject: display functions