Welcome Guest, Not a member yet? Register   Sign In
Database naming conventions
#47

[eluser]pashj[/eluser]
I'm no expert, by any means. But I prefer prepending the table name to the columns as the original poster suggested. The reason being duplicate column names in different tables. EX.

Code:
PRODUCT TABLE
product.id
product.title
product.description
etc...

CATEGORY TABLE
category.id
category.title
category.description
etc...

QUERY
select * from product p join category c on p.id=c.id;

The result for 'title' and 'description' come from the product table. You could reverse the join, then the result for duplicate columns would come from the category table. (To be fair, both columns are retrieved, but only one can be accessed via the name. You can get both by using an index.)

OK, so what do I do if I wanted both titles and descriptions? Yes, aliases would do the trick:
Code:
select
p.title as `product_title`,
p.description as `product_description`,
c.title as `category_title`,
c.description as `category_description`
from
product p join category c on p.id=c.id;

But this means every query needs to be carefully constructed (time, effort, possibility for bugs). It seems like the long way around. If the column names were already prepended with the table name
Code:
product.product_id
product.product_title
product.product_description
etc...

Then the result set would be unique with no extra work. I can continue to use select * queries. I can add/remove columns without having to dig through the code and make changes.

It just works. It's verbose, but it works. IMHO


Messages In This Thread
Database naming conventions - by El Forum - 05-13-2009, 09:34 AM
Database naming conventions - by El Forum - 05-13-2009, 09:45 AM
Database naming conventions - by El Forum - 05-13-2009, 11:19 AM
Database naming conventions - by El Forum - 05-13-2009, 11:31 AM
Database naming conventions - by El Forum - 05-13-2009, 12:01 PM
Database naming conventions - by El Forum - 05-13-2009, 12:02 PM
Database naming conventions - by El Forum - 05-13-2009, 12:10 PM
Database naming conventions - by El Forum - 05-13-2009, 12:16 PM
Database naming conventions - by El Forum - 05-13-2009, 12:17 PM
Database naming conventions - by El Forum - 05-13-2009, 05:05 PM
Database naming conventions - by El Forum - 05-13-2009, 06:58 PM
Database naming conventions - by El Forum - 05-14-2009, 12:56 AM
Database naming conventions - by El Forum - 05-14-2009, 01:17 AM
Database naming conventions - by El Forum - 05-14-2009, 02:02 AM
Database naming conventions - by El Forum - 05-14-2009, 02:16 AM
Database naming conventions - by El Forum - 05-14-2009, 02:20 AM
Database naming conventions - by El Forum - 05-14-2009, 10:39 AM
Database naming conventions - by El Forum - 05-14-2009, 01:17 PM
Database naming conventions - by El Forum - 05-14-2009, 10:01 PM
Database naming conventions - by El Forum - 05-14-2009, 11:10 PM
Database naming conventions - by El Forum - 05-14-2009, 11:20 PM
Database naming conventions - by El Forum - 05-15-2009, 02:12 AM
Database naming conventions - by El Forum - 05-15-2009, 05:26 AM
Database naming conventions - by El Forum - 05-15-2009, 05:39 AM
Database naming conventions - by El Forum - 05-15-2009, 05:43 AM
Database naming conventions - by El Forum - 05-15-2009, 05:50 AM
Database naming conventions - by El Forum - 05-15-2009, 05:50 AM
Database naming conventions - by El Forum - 05-15-2009, 05:57 AM
Database naming conventions - by El Forum - 05-15-2009, 06:15 AM
Database naming conventions - by El Forum - 05-15-2009, 06:20 AM
Database naming conventions - by El Forum - 05-15-2009, 06:22 AM
Database naming conventions - by El Forum - 05-15-2009, 06:53 AM
Database naming conventions - by El Forum - 05-15-2009, 06:56 AM
Database naming conventions - by El Forum - 05-15-2009, 08:36 AM
Database naming conventions - by El Forum - 05-15-2009, 08:42 AM
Database naming conventions - by El Forum - 05-15-2009, 08:46 AM
Database naming conventions - by El Forum - 05-15-2009, 08:49 AM
Database naming conventions - by El Forum - 05-15-2009, 09:02 AM
Database naming conventions - by El Forum - 05-15-2009, 09:23 AM
Database naming conventions - by El Forum - 05-15-2009, 10:00 AM
Database naming conventions - by El Forum - 05-15-2009, 12:10 PM
Database naming conventions - by El Forum - 05-15-2009, 01:10 PM
Database naming conventions - by El Forum - 05-15-2009, 01:36 PM
Database naming conventions - by El Forum - 05-20-2009, 05:03 PM
Database naming conventions - by El Forum - 09-28-2009, 05:46 PM
Database naming conventions - by El Forum - 09-30-2009, 05:30 PM
Database naming conventions - by El Forum - 11-29-2009, 07:17 AM
Database naming conventions - by El Forum - 11-29-2009, 08:29 AM
Database naming conventions - by El Forum - 11-29-2009, 12:46 PM
Database naming conventions - by El Forum - 07-12-2011, 01:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB