社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

MySQL——表中有很多列——需要建议

The Cool Cat • 3 年前 • 1235 次点击  

我想询问关于我的一个数据库表的建议。下面是 create 我的表名为 io_generated 其中包含 30多列 .我的问题是有这样的列好吗?还是我应该在不同的表中分隔一些数据?我在用VB。net在我的数据库中插入数据,我正在使用OOP。这是个好习惯吗?或者,为了创造一张漂亮的桌子,是否有任何建议?

桌子上有 8 logs ,4次输入和4次输出日志。每根圆木都有 branch_id (branch1…branch8)我还有一列来确定 log is edited (in1_编辑…out4_编辑),还有 Late , Undertime total working hours .都在这张桌子上。

提前谢谢!非常感谢你的帮助。

CREATE TABLE `io_generated` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `employee_id` int(11) unsigned DEFAULT NULL,
  `date` date DEFAULT NULL,
  `branch_id` mediumint(8) unsigned DEFAULT NULL,
  `in1` datetime DEFAULT NULL,
  `out1` datetime DEFAULT NULL,
  `in2` datetime DEFAULT NULL,
  `out2` datetime DEFAULT NULL,
  `in3` datetime DEFAULT NULL,
  `out3` datetime DEFAULT NULL,
  `in4` datetime DEFAULT NULL,
  `out4` datetime DEFAULT NULL,
  `branch1` mediumint(8) unsigned DEFAULT NULL,
  `branch2` mediumint(8) unsigned DEFAULT NULL,
  `branch3` mediumint(8) unsigned DEFAULT NULL,
  `branch4` mediumint(8) unsigned DEFAULT NULL,
  `branch5` mediumint(8) unsigned DEFAULT NULL,
  `branch6` mediumint(8) unsigned DEFAULT NULL,
  `branch7` mediumint(8) unsigned DEFAULT NULL,
  `branch8` mediumint(8) unsigned DEFAULT NULL,
  `in1_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `out1_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `in2_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `out2_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `in3_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `out3_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `in4_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `out4_edited` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `late1` decimal(10,2) NOT NULL DEFAULT '0.00',
  `late2` decimal(10,2) NOT NULL DEFAULT '0.00',
  `late3` decimal(10,2) NOT NULL DEFAULT '0.00',
  `late4` decimal(10,2) NOT NULL DEFAULT '0.00',
  `total_late` decimal(10,2) NOT NULL DEFAULT '0.00',
  `hrs1` decimal(10,2) NOT NULL DEFAULT '0.00',
  `hrs2` decimal(10,2) NOT NULL DEFAULT '0.00',
  `total_whrs` decimal(10,2) NOT NULL DEFAULT '0.00',
  `ot_hrs` decimal(10,2) NOT NULL DEFAULT '0.00',
  `ut1` decimal(10,2) NOT NULL DEFAULT '0.00',
  `ut2` decimal(10,2) NOT NULL DEFAULT '0.00',
  `ut3` decimal(10,2) NOT NULL DEFAULT '0.00',
  `ut4` decimal(10,2) NOT NULL DEFAULT '0.00',
  `total_ut` decimal(10,2) NOT NULL DEFAULT '0.00',
  `day_count` double(10,2) NOT NULL DEFAULT '0.00',
  PRIMARY KEY (`id`),
  UNIQUE KEY `employee_id` (`employee_id`,`id`,`date`,`branch_id`),
  KEY `branch_id` (`branch_id`),
  KEY `branch1` (`branch1`),
  KEY `branch2` (`branch2`),
  KEY `branch3` (`branch3`),
  KEY `branch4` (`branch4`),
  KEY `branch5` (`branch5`),
  KEY `branch6` (`branch6`),
  KEY `branch7` (`branch7`),
  KEY `branch8` (`branch8`),
  CONSTRAINT `io_generated_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `employee` (`Employee_ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `io_generated_ibfk_10` FOREIGN KEY (`branch8`) REFERENCES `branch` (`Branch_ID`),
  CONSTRAINT `io_generated_ibfk_2` FOREIGN KEY (`branch_id`) REFERENCES `branch` (`Branch_ID`) ON UPDATE CASCADE,
  CONSTRAINT `io_generated_ibfk_3` FOREIGN KEY (`branch1`) REFERENCES `branch` (`Branch_ID`),
  CONSTRAINT `io_generated_ibfk_4` FOREIGN KEY (`branch2`) REFERENCES `branch` (`Branch_ID`),
  CONSTRAINT `io_generated_ibfk_5` FOREIGN KEY (`branch3`) REFERENCES `branch` (`Branch_ID`),
  CONSTRAINT `io_generated_ibfk_6` FOREIGN KEY (`branch4`) REFERENCES `branch` (`Branch_ID`),
  CONSTRAINT `io_generated_ibfk_7` FOREIGN KEY (`branch5`) REFERENCES `branch` (`Branch_ID`),
  CONSTRAINT `io_generated_ibfk_8` FOREIGN KEY (`branch6`) REFERENCES `branch` (`Branch_ID`),
  CONSTRAINT `io_generated_ibfk_9` FOREIGN KEY (`branch7`) REFERENCES `branch` (`Branch_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

In1到Out4与Branch1到BRANCH8以及In1_编辑到Out4_编辑相关。每个输入/输出都有相应的分支和编辑标识符。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/128403
 
1235 次点击  
文章 [ 2 ]  |  最新文章 3 年前