|
Posted by Toby Inkster on 05/14/06 15:27
Dikkie Dik wrote:
> Toby Inkster wrote:
>
>> For example, if I'm keeping a table of my customers' credit cards, I might
>> use:
>>
>> customer_id (int, foreign key)
>> card_number (big int, primary key)
>> card_holder_name (varchar)
>> expiry_date (timestamp)
>>
>> If I'm inserting a new record into the table then I already know the
>> primary key, don't I?
>
> No, you don't. You know a FIELD value of your record, NOT its primary
> key.
Look at the table structure. The credit card number *is* the primary key.
If I know the card details, I know the primary key.
> Especially, primary key values should never be related to the data in
> the record.
Yes it should.
Any field, or combination thereof, that will never be null and where
values will always be unique in a particular table is a "candidate key".
Any candidate key can be chosen to be the primary key.
In my example above, if I'm never going to need to store the same credit
card number twice, then I can use the card number as a primary key.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|