在 SQLite 中实现子项

发布于 2024-10-10 04:32:34 字数 436 浏览 0 评论 0原文

我如何实现一个子项目,其中该项目将具有同一项目的父项目。例如,我有一个保存任务/待办事项的数据库。每个待办事项都有一个标题 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过潦 2024-10-17 04:32:34

我会同意你最后的想法。通过添加“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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文