Best practise database prefixes in tables?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Best practise database prefixes in tables?



I have a database which has users and a todo list for these user (and a lot more tables but that's irrelevant).



A user can have multiple todo items but an item can only be linked to one user.



I was wondering how to create a table for the todo items?

- Should I just call it something like: todo-items

- As it is for users should I call it: users_todoitems

- Should I give it a prefix, like: u_todoitems?



I tried searching for best practices regarding these type of problems, but couldn't find a good answer.





Just call it todos, or change the terminology to tasks.
– mul14
Aug 8 at 7:58


todos


tasks





@mul14 Even if only users use this table?
– Kerwin Sneijders
Aug 8 at 8:01






How many type of users do you have?
– mul14
Aug 8 at 8:13





The table is used by all users. I am unsure about what you mean with 'type of users'.
– Kerwin Sneijders
Aug 8 at 8:30





What I meant was—maybe you have teachers, soldiers, etc. Each user type have their own todos. For example teacher_todos, soldier_todos. If only 1 type of users, it's fine name it as todos.
– mul14
Aug 8 at 11:01


teachers


soldiers


teacher_todos


soldier_todos


todos




1 Answer
1



Having different user tables is upto how normalized you want your db design to be.
If you think deep, todos are actually a list which can have more than one task. So, it's more logical to connect todo list to user rather than connecting tasks. So, one user can have more than one todo list and each todo list can have more than one task.



I would advise to go with the following table design:



users table


users



user_todo_lists table


user_todo_lists



todo_list_tasks table


todo_list_tasks



This design works well even for your worst query of an user not having even one todo task. In such case your search is limited to user_todo_lists table and not the massive todo_list_tasks table.


user


user_todo_lists


todo_list_tasks





In my case a user does not have more than one todo list. So I don't think I need to 'seperate' the list from the items. However, is it a bad practice having a list of todoitems linked directly to a user? Would it be better to create a list and the items to that list? Because it sounds like it would be faster database wise.
– Kerwin Sneijders
Aug 10 at 8:45





If you anticipate many users to not have any task associated to them, then go ahead and create the list table.It will save your from searching your entire table to return no record exists for user who haven't created a task.
– Hari Harker
Aug 12 at 21:04






Forgot to mark as answer, thanks for the explanation
– Kerwin Sneijders
Aug 15 at 8:31






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS