At 11:15 -0400 6/19/03, Mojtaba Faridzad wrote:
Hi,

In a docuement such as Invoice Form, we have a header and a couple of
records for the detail. In header table, Invoice# can be the PRIMARY KEY but
in detail table, Invoice# is not unique. I think there are two solutions to
choose a Primary Key (in MyISAM type) :

1) Adding an id field ( auto_increment ) and choose it as PRIMARY KEY
in this case we have to add another index on Invoice# for making relation
with the header table

2) There is another field in detail table with "timestamp" type for keeping
the last change on the record. I want to select ( Invoice# + myTimestamp )
for PRIMARY KEY. in this case I don't need to add a new fields ( id ) and
another index ( on Invoice# ) to the table.

which one do you prefer and usually use?

Don't use 2). There is no guarantee a TIMESTAMP value will be unique among records with the same invoice number. That means invoice number + timestamp wil not form a PRIMARY KEY.

I'd use 1), possibly combining the invoice number with the item id as
a composite key.


-- Paul DuBois, Senior Technical Writer Madison, Wisconsin, USA MySQL AB, www.mysql.com

Are you MySQL certified? http://www.mysql.com/certification/


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to