SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Nov 6, 2009, 05:17 #1
Best practices for using mysql field names.
Best practices for using mysql field names.
CASES:
1>Type1
Code:--------- users --------- id first_name last_name email password ----------
2> Type2
Code:--------- users --------- user_id user_first_name user_last_name user_email user_password ----------
I would like to know the opinions of forumians that which naming conventions (among two as shown above)
do you deploy and why?
Thanks
-
Nov 6, 2009, 08:01 #2
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
never, ever option 2
embedding the table name into the column name is unnecessary, wasteful, and above all, obfuscating
it makes queries ~so~ much harder to read
-
Nov 10, 2009, 05:58 #3
-
Nov 29, 2009, 03:36 #4
- Join Date
- Mar 2008
- Location
- London
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
So what do you do in the situation where you have two tables such as 'product' and 'category' and they both have a column named 'description'. If you do a simple * and join the tables, the resulting set of data will have a duplicate field.
Code:select * from product p, category c where p.id=c.id;
Yes you could do this:
Code:select p.description as `product.description`, c.description as `category.description` etc..
But that means any time you change the database, you have to update all your data access code.
Is it recommended to alias each column on every query as I've done in the 2nd query above?
-
Nov 29, 2009, 06:29 #5
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
Bookmarks