简体   繁体   English

SQL 数据库设计时间表员工与工作人员

[英]SQL Database Design Timesheet Employee vs Crews

First question here so please let me know how to ask the question better if below is unhelpful.这里的第一个问题所以如果下面没有帮助,请让我知道如何更好地提出问题。

TLDR - Should I have separates employee times tables for employees assigned to crews and those who are not? TLDR - 我应该为分配给工作人员的员工和没有工作的员工分别制定员工时间表吗?

I'm trying to design database, following 'Database Design for mere mortals' book, that tracks employees times.我正在尝试设计数据库,遵循“普通人的数据库设计”一书,跟踪员工时间。 I'm trying to replace the weekly timesheets and crew paper sheets (with start & end times for the crew) being used.我正在尝试更换正在使用的每周时间表和船员纸(带有船员的开始和结束时间)。 There are also individual employee weekly timesheets for those not assigned to crews.对于未分配给工作人员的人员,还有个别员工每周时间表。 Also crew sheets sometimes have an asterisk with if someone is sick etc.如果有人生病等,船员工作表有时也会带有星号。

There is a relationship of Projects to crews (1:N) and for the individual employee not assigned to crews are assigned to the project.项目与工作人员之间存在关系 (1:N),未分配给工作人员的单个员工被分配给项目。 Employees are assigned to crews, normally 1:1 but headache comes when 1:N.员工被分配到机组人员,通常是 1:1,但当 1:N 时就会头疼。

'Has' Relationships “有”关系

So at the moment the are different types of crews say A, B, C, D, E.所以目前有不同类型的工作人员说 A、B、C、D、E。

Crews D & E will just fill in weekly timesheets (project, names and times, so crews D and E will both be on this same project) and the daily sheets don't include times. Crews D & E 将只填写每周时间表(项目、名称和时间,因此工作人员 D 和 E 都将参与同一个项目)并且每日工作表不包括时间。 Sometimes like 10% of the time employees will be on both D & E on the same day.有时大约 10% 的员工会在同一天同时参加 D&E。

A, B, C will have daily times on the daily sheet, but if an employee is on crew C these times take precedance over the times on sheets A or B (if they are also on A or B). A、B、C 将在每日工作表上有每日时间,但如果员工在 C 组,这些时间优先于工作表 A 或 B 上的时间(如果他们也在 A 或 B 上)。

The obvious answer to have {employee, datetimestart, datetimeend} won't work as I care where the times have come from (crew, individual if exception to the crew eg sick, individual not assigned to a crew). {employee, datetimestart, datetimeend} 的显而易见的答案是行不通的,因为我关心时间的来源(船员、个人,如果船员例外,例如生病、未分配给船员的个人)。

I can extend to have {employee, crewtype, datetimestart, datetimeend} this doesn't take care of when employee is both on D & E. I can put DE or F in this case?我可以扩展到 {employee,crewtype,datetimestart,datetimeend},当员工同时在 D 和 E 上时,这不会处理。在这种情况下,我可以放 DE 还是 F?

Then how do I deal with those assigned to the project only?那么我如何处理那些只分配给项目的人呢? if I have {employee, crewtype, projectref, datetimestart, datetimeend} the projectref is redudant and can be derived from crewtype when this is not null.如果我有 {employee、crewtype、projectref、datetimestart、datetimeend},则 projectref 是冗余的,并且可以在不为 null 时从crewtype 派生。 Is this a reasonable approach or would having separate tables be better?这是一种合理的方法还是单独的表格会更好?

EDIT - or should I have one table {crewid, datetimestart, datetimeend} - derive the times for employees from the crew-employee relationship, and have a separate {employee, datetimestart, datetimeend, category} with category saying if exception (eg sick) or non-assigned individual?编辑- 或者我应该有一张表 {crewid, datetimestart, datetimeend} - 从船员 - 员工关系中导出员工的时间,并有一个单独的 {employee, datetimestart, datetimeend, category} 类别说明是否有异常(例如生病)或非指定个人?

There are a lot of complicated rules in this description.这个描述中有很多复杂的规则。 If you want to create a schema that will never break these rules it will likely be a very complicated normalised schema.如果你想创建一个永远不会违反这些规则的模式,它可能是一个非常复杂的规范化模式。 I would suggest that some of the rules will be best catered for in your application logic.我建议在您的应用程序逻辑中最好地满足某些规则。

In terms of how you store the date, remember that you always need to cater for the exception cases, so something that happens 10% of the time, or 1% or one in a thousand still needs to be catered for, otherwise you just cant save the data.就你如何存储日期而言,记住你总是需要照顾例外情况,所以10%的时间发生的事情,或者1%或千分之一仍然需要照顾,否则你就不能保存数据。

I would tend to design for the most detailed level, which might be employee,crew,project,date,times, and possible also add an allocation column that defaults to 1, but could be 0.5 if the person is half allocated to two crews at the same time.我倾向于为最详细的级别进行设计,这可能是员工、船员、项目、日期、时间,也可能添加一个默认为 1 的分配列,但如果该人一半分配给两个船员,则可能是 0.5同时。

You could then write queries so that if a person is allocated to a crew, they get the crew time by default unless they have some overridden values, or whatever other rules you need.然后,您可以编写查询,以便如果一个人被分配给一个工作人员,他们会默认获取工作人员时间,除非他们有一些覆盖值或您需要的任何其他规则。

Really, this is the sort of iterative modelling you would do with your business users as you tease out the design.确实,这是您在梳理设计时与业务用户进行的那种迭代建模。 Not always easy in a real-world scenario.在现实世界的场景中并不总是那么容易。

Sorry there is no definitive model here, but maybe a few tips to consider that might help along the way.抱歉,这里没有明确的模型,但也许需要考虑的一些提示可能会有所帮助。 Good luck with it.祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM