database schema for timesheet

前端 未结 5 1905
青春惊慌失措
青春惊慌失措 2021-02-02 03:17

Could someone help me with a rough database schema for a timesheet application where the i would be able to

  1. Store hours per day for a time period ( 2 weeks ) fo

5条回答
  •  不思量自难忘°
    2021-02-02 03:53

    Borrowing from Eric Petroelje & mdma:

    Employee 
    - EmployeeID (PK)
    - EmployeeName
    - Other_fields
    
    Project
    - ProjectID (PK)
    - ProjectName
    - Other_fields
    
    WorkSegment
    - WorkSegmentID (PK)
    - ProjectID (IX1)
    - EmployeeID (IX2)
    - Date (IX1, IX2)
    - StartTime 
    - EndTime
    - PayrollCycleID (FK)
    

    The first index of WorkSegment is ProjectID, Date. The second index of WorkSegment is EmployeeID, Date. These indexes are not unique. This is so a person can work on a project more than once in one day. The indexes allow for reporting on hours worked by project or by person.

    Each WorkSegment row is for one segment of time, one day, one project. Each employee has as many WorkSegment rows as is needed to describe his payroll cycle.

    TimeSheetSegment
    - TimeSheetSegmentID (PK)
    - ProjectId (FK)
    - EmployeeId (FK)
    - PayrollCycleID (FK)
    

    There is a unique index on ProjectID, EmployeeID, and PayrollCycleID. There is one TimeSheetSegment row for each project that an employee works for during a payroll cycle.

    TimeSheet
    - TimeSheetID (PK)
    - EmployeeID (IX)
    - PayrollCycleID (IX)
    

    The TimeSheet row brings the TimeSheetSegment and WorkSegment rows together. The EmployeeID, PayrollCycleID index is unique.

    Approval
    - TimeSheetID (PK)
    - PayrollCycleID (FK)
    - SubmittedTimestamp
    - ApproverID (FK)
    - ApprovedTimestamp
    

    The Approval row is created when the time sheet is submitted. These fields could be part of the TimeSheet table. I broke them out with a fourth-order normalization because the Approval table is likely to have different database access permissions than the TimeSheet table.

    PayrollCycle
    - PayrollCycleID (PK)
    - PayrollCycleYear
    - PayrollCycleNumber
    - StartDate 
    - EndDate
    - DirectDepositDate
    - CheckDate
    - Other_fields
    

    The PayrollCycle table normalizes some of the date fields, and provides an integer key that makes it easier to pull together the WorkSegment and TimeSheetSegment rows to make a coherent time sheet.

提交回复
热议问题