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

[eluser]tekhneek[/eluser]
A little late but who cares, this is how I handle my "database" (I'd usually call them databases, but pluralization is apparently the devils.)

Table naming conventions
- Plural (e.g. "users")
- 1:* relationships are: "table1_table2" (e.g. "users_categories" maintaining pluralization throughout.)

I don't use the alphabetical approach because "categories_users" sounds confusing to me where as "users_categories" sounds logical and you can immediately understand the significance (at least I can) of that naming convention.

You could say "users have categories/categories have users"... I mean does the dog wag the tail or does the tail wag the dog?

- *:* relationships are spread over 3 tables (almost always)
Table 1: photos
Table 2: photo_galleries
Table 3: photo_galleries_photos

Column conventions
- Always lowercase
- alpha-underscore
- Primary keys are always first -- "id" (e.g. users.id)
- Foreign keys are always fk_table_id (e.g. fk_user_id) following any primary id. (Pluralization is stripped to signify a single relationship.)
- Last column is always "created" datetime/timestamp regardless of table significance albeit joining, primary, secondary, tertiary, etc.

photo_galleries_photos example
fk_photo_galleries_id
fk_photo_id
created

That's my two cents.


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