Re: primary and foregin keys
Date: 24 Dec 2004 01:58:59 -0800
Message-ID: <1103882339.654703.168080_at_c13g2000cwb.googlegroups.com>
rallykarro_at_hotmail.com wrote:
> As far as I understand the primary key shold be set on the columns
> which make the rows in the table unique?!
> Since I want history tracking of my products the valid post is
actually
> the one with the latest date. This is why the product_number is not
> unique itself in my "product" table.
True. But if you want history tracking per product then you need 2 tables:
create table product (prod_number integer constraint pk_prod primary key, ...);
create table product_history (prod_number references product ,
prod_date date,
..., constraint pk_prod_hist primary key (prod_number, prod_date));
Now you storage table can have a foreign key to the product table.
Received on Fri Dec 24 2004 - 10:58:59 CET