some respects, a table isn't a table if it has no primary key
constraint. In mathematics, it's the difference between a set and a
bag -- a bag permits duplicates, whereas a set doesn't.
Relational database tables should be like sets, where each row in the
table represents in a fact or statement. C. J. Date said, "once you
know a fact, stating it again doesn't make it any more true." To
which a student replied, "you can say that again!"
Practically, a primary key is the means to address individuals rows,
for example the find() method and the save() method assume they can
map Row objects in your PHP code to rows in the database using a
primary key. All tables must have a primary key to be used in the ORM
framework.
That's why if you declare no primary key in your Zend_Db_Table class,
and it can't discover the primary key by querying metadata, it throws
an exception.
If you have a table with no primary key constraint, SQL permits this,
but you'll have to write the SQL yourself instead of using
Zend_Db_Table methods.
Regards,
Bill Karwin
On Jun 2, 2010, at 5:48 AM, Vincent de Lau wrote:
> I'd say that in a properly designed database, nearly any table
> should have a primary key of some sort. 80/20 seems to be a bit too
> low, I'd say that 99% of the tables will can have a primary key.
没有评论:
发表评论