Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL naming conventions, should field name include the table name?

A friend told me that I should include the table name in the field name of the same table, and I'm wondering why? And should it be like this? Example:

(Table) Users  
(Fields) user_id, username, password, last_login_time

I see that the prefix 'user_' is meaningless since I know it's already for a user. But I'd like to hear from you too. note: I'm programming in php, mysql.

like image 673
Omar Al-Ithawi Avatar asked Aug 23 '09 10:08

Omar Al-Ithawi


1 Answers

I agree with you. The only place I am tempted to put the table name or a shortened form of it is on primary and foreign keys or if the "natural" name is a keyword.

Users: id or user_id, username, password, last_login_time
Post: id or post_id, user_id, post_date, content

I generally use 'id' as the primary key field name but in this case I think user_id and post_id are perfectly OK too. Note that the post date was called 'post_date" because 'date' is a keyword.

At least that's my convention. Your mileage may vary.

like image 75
cletus Avatar answered Sep 24 '22 13:09

cletus