简体   繁体   中英

Naming conventions for MySQL tables

I would like to get some opinions since I am thinking about creating structure for my new application and I am struggling with names for tables so I thought maybe you can give me some ideas. App has users and users can create projects while projects can have multiple keywords. So users are in one-to-many relationship with projects and projects are in many-to-many relationships with tags.

So having table users I suppose projects table should be users_projects . But what about keywords? Should it be users_projects_keywords ? And what about pivot table since I think it is kinda bad to name it like users_projects_to_users_projects_keywords or something like that. I would be grateful for a tips.

Edit: I always thought that one-to-many relationships should be called like x_y where y belongs to x. Is it not a good practice ?

I would have users , projects , keywords , project_keywords . I would use foreign keys to define the relationships between the tables. For example, projects would have a column such as createdby_userid , referring to the users.user_id column.

One idea:

There could be three dictionaries:

  • Table users should have id and other data.
  • Table projects as well.
  • And so table keywords .

Then you create "linking" (relations) tables:

  • users_projects with column id, id_user, id_project
  • projects_keywords with id, id_project, id_keyword

EDIT : Maybe it indeed would be rational to include id_user into table projects as mentioned by @Laurence.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM