如果在另一个表中没有匹配则用作外键 - MySQL

时间:2021-05-13 10:18:06

I am working on an attendance/overtime module for a schedule web app. The idea is that there is a table in MySQL of shifts, each shift having a start and end time. The manager will choose a shift and make an entry into the attendance table specifying whether the employee was early/late/left early/worked overtime. That entry in the attendance table is keyed to the shifts ID # (which is just an enumerated key).

我正在为计划网络应用程序的出勤/加班模块工作。我们的想法是在MySQL中有一个表格,每个班次都有一个开始和结束时间。经理将选择班次并进入考勤表,指定员工是早/迟/早退/加班。出勤表中的该条目与班次ID#(仅为枚举密钥)相关联。

But if someone comes in on their day off, there is no shift to key it to. What is a good system to use for those keys? Ccan I set up a conditional enumeration? And how do I avoid the risk of overlap with a shift ID? Adding the overtime shift back into the original schedule DB is not an option.

但是,如果有人在休息日进来,那就没有任何关键。什么是用于这些键的好系统?我可以设置条件枚举吗?如何避免与班次ID重叠的风险?将加班转移回原始计划DB不是一种选择。

2 个解决方案

#1


Similar to your previous question, if there is no data, then NULL is appropriate. In this case the work isn't attached to a particular shift so what else can you put there? And again the status should reflect this.

与前一个问题类似,如果没有数据,则NULL是合适的。在这种情况下,工作不附加到特定的班次,那么你还能把它放在那里?状态应该反映这一点。

#2


What's wrong with adding an additional key to your enum column? That shouldn't hurt existing code, and seems the best solution to me.

在枚举列中添加额外的键有什么问题?这不应该伤害现有代码,对我来说似乎是最好的解决方案。

#1


Similar to your previous question, if there is no data, then NULL is appropriate. In this case the work isn't attached to a particular shift so what else can you put there? And again the status should reflect this.

与前一个问题类似,如果没有数据,则NULL是合适的。在这种情况下,工作不附加到特定的班次,那么你还能把它放在那里?状态应该反映这一点。

#2


What's wrong with adding an additional key to your enum column? That shouldn't hurt existing code, and seems the best solution to me.

在枚举列中添加额外的键有什么问题?这不应该伤害现有代码,对我来说似乎是最好的解决方案。