mysql - 用于任务管理的数据库架构

标签 mysql

我必须管理一个待办事项列表,并且我正在寻找在我的 MySQL 数据库中实现它的最佳方法。

我的待办事项列表如下

  • 手术前
    • 任务1
    • 任务2
    • 任务3
    • 任务4
  • 收据图像和数据
    • 任务1
    • 任务2
  • ...
  • ...
  • 术后
    • 任务1
    • 任务 2

我正在考虑像这样构建我的架构:

*************
*** steps ***
*************
id_step 
name_step 

1|Pre-op
2|Receipt images and data
3|...
8|Post-op

*************
*** tasks ***
*************
id_task 
name_task 

1|Task1
2|Task2
3|...
8|Task56

****************
*** todolist ***
****************
id_todolist 
step_id 
task_id
state 

1|1|1|archived
2|1|2|current
3|...
x|8|56|current

我做得对吗?或者有更好的方法进行吗?

不同的任务是独特的。最后我至少会有两个这样的列表。

我管理外科手术。目前已申请两项专利。这是管理操作的两种不同方式。 future ,我们可以想象还会申请其他专利。

最佳答案

也许这有点晚了:D但是..

我假设你想要这样的东西: Todolist er diagram

以下是如何使用一些演示数据来创建此设置以清空数据库:

CREATE TABLE `todolists` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `description` text,
  `order` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `order` (`order`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

INSERT INTO `todolists` (`id`, `name`, `description`, `order`) VALUES
    (1, 'todolist1name', NULL, 1),
    (2, 'todolist2name', NULL, 2);

CREATE TABLE `steps` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `description` text,
  `todolist_id` int(11) NOT NULL,
  `order_in_todolist` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `step_order_in_todolist` (`todolist_id`,`order_in_todolist`),
  CONSTRAINT `FK1: belong to todolist` FOREIGN KEY (`todolist_id`) REFERENCES `todolists` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `steps` (`id`, `name`, `description`, `todolist_id`, `order_in_todolist`) VALUES
    (1, 'step11name', NULL, 1, 1),
    (2, 'step12name', NULL, 1, 2),
    (3, 'step13name', NULL, 1, 3),
    (6, 'step14name', NULL, 1, 4),
    (7, 'step21name', NULL, 2, 1),
    (8, 'step22name', NULL, 2, 2),
    (9, 'step23name', NULL, 2, 3);

CREATE TABLE `states` (
  `name` char(20) NOT NULL,
  PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `states` (`name`) VALUES
    ('Archived'),
    ('Current');

CREATE TABLE `tasks` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `description` text,
  `state` char(20) NOT NULL,
  `step_id` int(11) NOT NULL,
  `order_in_steplist` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `Unique order in steplist` (`step_id`,`order_in_steplist`),
  KEY `FK1: reference states` (`state`),
  CONSTRAINT `FK1: reference states` FOREIGN KEY (`state`) REFERENCES `states` (`name`),
  CONSTRAINT `FK2: belongs to step` FOREIGN KEY (`step_id`) REFERENCES `steps` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `tasks` (`id`, `name`, `description`, `state`, `step_id`, `order_in_steplist`) VALUES
    (1, 'Task111name', NULL, 'Archived', 1, 1),
    (2, 'Task112name', NULL, 'Current', 1, 2),
    (3, 'Task113name', NULL, 'Current', 1, 3),
    (4, 'Task114name', NULL, 'Current', 1, 4),
    (5, 'Task121name', NULL, 'Current', 2, 1),
    (6, 'Task122name', NULL, 'Current', 2, 2),
    (7, 'Task123name', NULL, 'Current', 2, 3),
    (8, 'Task131name', NULL, 'Current', 3, 1),
    (9, 'Task132name', NULL, 'Current', 3, 2),
    (10, 'Task133name', NULL, 'Current', 3, 3),
    (12, 'Task141name', NULL, 'Current', 6, 1),
    (13, 'Task142name', NULL, 'Current', 6, 2),
    (14, 'Task143name', NULL, 'Current', 6, 3),
    (15, 'Task211name', NULL, 'Archived', 7, 1),
    (16, 'Task212name', NULL, 'Archived', 7, 2),
    (17, 'Task213name', NULL, 'Archived', 7, 3),
    (18, 'Task221name', NULL, 'Archived', 8, 1),
    (19, 'Task222name', NULL, 'Archived', 8, 2),
    (20, 'Task223name', NULL, 'Current', 8, 3),
    (21, 'Task231name', NULL, 'Current', 9, 1),
    (22, 'Task232name', NULL, 'Current', 9, 2),
    (23, 'Task233name', NULL, 'Current', 9, 3);

CREATE VIEW `show_all_list_with_steps_and_tasks` AS SELECT `todolists`.`order` AS `todolist_number`, `todolists`.`name` AS `todolist_name`, `steps`.`order_in_todolist` AS `step_order`, `steps`.`name` AS step_name, `tasks`.`order_in_steplist` AS `task_order`, `tasks`.`name` AS `task_name`, `tasks`.`state`
FROM `todolists` JOIN `steps` ON `todolists`.`id` = `steps`.`todolist_id` JOIN `tasks` ON `steps`.`id` = `tasks`.`step_id` 
ORDER BY `todolist_number`, `step_order`, `task_order` ;

关于mysql - 用于任务管理的数据库架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28835171/

相关文章:

php - 如何在 mysql 中将 2 个 sql 语句组合成一个查询?

Mysql查询,在周数列中获取结果,老化桶报告的种类

python - 只想在 python 中显示 mySQL 结果的 3 行

mysql - 带 COUNT 的 LEFT JOIN 返回意外值

c# - 从 mysql 检索保存的图像时出现参数无效错误 c#

mysql - 从 SQL 选择月份和年份

php - MySQL获取所有有 child 的 parent

Mysql唯一值查询

php - WampServer 2.4 MySQL 实例未启动,图标保持橙色

javascript - 使用 jquery 对话框中的 html 表单更新 mysql 中的数据