Originally Posted by Old Pedant
Well, of course I never use id
as a primary key column name. I always include part of the table name in my primary key columns.
CREATE TABLE users (
userid INT AUTO_INCREMENT PRIMARY KEY,
CREATE TABLE products (
prodid INT AUTO_INCREMENT PRIMARY KEY,
and so on.
I do this so that my foreign keys can use the same names, thus making the PK/FK relationships both more obvious and more readable.
But that's up to you.
Have to disagree on this one...
I take this approach...
All of the Fields above are adjectives to the Table which is the noun (e.g. MEMBER.location).
It is redundant to say MEMBER.member_id
Notice how in my Junction Table my Foreign Key fields are a concatenation of the Parent Entity (i.e. "article" and "member") and Field itself (i.e. "id and "id")?
So anytime you are looking at FK fields, you can easily see the Parent Table.Key combination.
ARTICLE.id -||-----|<- ARTICLE_THREAD.article_id
MEMBER.id -||-----|<- ARTICLE_THREAD.member_id
Just as easy to read - in my opinion - and more streamlined...