在 SQLite 中实现子项
我如何实现一个子项目,其中该项目将具有同一项目的父项目。例如,我有一个保存任务/待办事项的数据库。每个待办事项都有一个标题 (TEXT
)、已完成 (INTEGER
[1 if true, 0 if false]) 和截止日期 (TEXT
)柱子。我想添加具有子任务的功能,其中任务可能有父任务。我如何在 Android 版 SQLite 中实现此功能? 不在 SQL 中!所以没有外键(不过允许触发器)!我可以有一个单独的表(子任务)并有一个外键触发器来将子任务(INTEGER Parent
)链接到任务(INTEGER PRIMARY KEY AUTOINCRMENT _id
)吗?或者我应该在原始任务表中添加一列(INTEGER Parent
)?我怎样才能实现这个?
How could I implement a sub item where the item would have a parent to that of the same item. For example, I have a database that holds tasks/todos. Each todo has a title(TEXT
), completed(INTEGER
[1 if true, 0 if false]), and due date(TEXT
) column. I would like to add functionality to have subtasks, where a task could possibly have a parent task. How would I implement this in SQLite for Android? NOT IN SQL! So no foreign keys (triggers are allow, though)! Could I just have a separate table (subtask) and have a foreign key trigger to link subtask(INTEGER parent
) to task(INTEGER PRIMARY KEY AUTOINCREMENT _id
)? Or should I add a column to my original task table(INTEGER parent
)? How could I implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会同意你最后的想法。通过添加“parnent”列和父任务的存储 ID 来修改原始表。
仅为子任务创建另一个表并不是最好的解决方案。如果您的子任务有自己的子任务,您会怎么做?
I would go with the last thought of yours. Modify your original table by adding column "parnent" and store ID of the parent task.
Creating another table just for sub-tasks wouldn't be the best solution. what will you do if your sub-task will have sub-tasks of it's own?