You are here: Re: Database abstraction layers « PHP Programming Language « IT news, forums, messages
Re: Database abstraction layers

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация