database design - What would be the advantages/disadvantages of prefixing column names with the item name? -


i working on blog module use in future project.

i decided prefix table names blog_ since it's module , different modules can have tables same name.

yesterday looking source code of ips boards , saw this. point interested me used prefixes column names too.

as example:

blog_categories     category_id     category_name     category_slug 

or

blog_categories     id     name     slug 

which 1 think better if it?

to extent flamewar territory, post discuss why think people choose 1 or other. in latter category. note pros , cons depend on database system.

reasons add prefixes

with prefixes, column names largely semantically unique. category_id refers id of category table. people think easier read. others point out allows joins use using () since means join columns have same name.

unfortunately latter case not perfect. using () limits planner can join since re-ordering joins can change join criteria. planners might able around however. check database documentation details.

reasons not add prefixes

i prefer not add prefixes. in model, columns logically bound primary key of table, using table namespace works allows simpler, more consistent naming regarding significance within table. numeric surrogate key example might called id while other columns may have other names.

part of preference may related choice of database. postgresql doesn't make hard distinction (the way innodb does) regarding primary key vs not null unique constraints. therefore find naming surrogate keys consistently nice, particularly when try designate natural primary keys. approach not work on database systems.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -