MySQL Best Practices Naming Conventions

Consider these simple tables:

id primary-key, auto-increment name varchar(256) +---------+ - tasks - +-------------------------------------------+ - id | name - +-------------------------------------------+ - 1 | Go to supermarket - - 2 | Buy cheese - - 3 | Buy PS4 and not Xbone - +-------------------------------------------+ id primary-key, auto-increment username unique varchar(128) +---------+ - users - +-------------------------------------------+ - id | username - +-------------------------------------------+ - 1 | dalejr - - 2 | firstnamelastname - +-------------------------------------------+ user_id fk, index task_id fk, index +---------------+ - users_tasks - +-------------------------------------------+ - user_id | task_id - +-------------------------------------------+ - 1 | 1 - - 1 | 2 - - 2 | 3 - +-------------------------------------------+ 
  • I always build table names and column names
  • I always use 'id' instead of 'task_id' if it is not a foreign key. I think tablename.tablename_id stupid.
  • I always index foreign keys, such as the users_tasks table.

How does this practice differ from the established MySQL agreement / best practice?

And more importantly ... is it bad?

+4
source share

Source: https://habr.com/ru/post/1487118/


All Articles