Say I have a table with the following schema:
CREATE TABLE tasks (taskID TEXT, username TEXT, completed BOOL)
The tasks table is likely to grow large, and users will frequently be viewing their completed tasks, and, on separate occasions looking at their history of completed tasks. This implementation would require an extra comparison every time a user wants to view one or the other (i.e. completed=”true”)
Is it better to have two tables like this:
CREATE TABLE ToDo (taskID TEXT, username TEXT)
CREATE TABLE completed(taskID TEXT, username TEXT)
Obviously, if this were the case, every time someone completes a task, a DELETE would happen in the ToDo table and an INSERT in the completed table.
I’m still a newbie in the ways of efficient SQL, so I don’t know which of these implementations is better. Any help?
I would keep them in one table. If you are new to database design I would recommend reading up on database normalization.
One thing I would change is your use of
TEXTfor both taskId and username. Are you sure thatintandvarcharwould not be better suited for these columns?