Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

> 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),
	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

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group