I have a question related to Database Design. Your inputs/suggestions will be greatly appreciated.
We have designed a Timesheet Table which tracks employees hours spent on various projects. We have split the Timesheet Data into 2 Tables => Timesheet & Timesheet Detail. The Table structure for the Timesheet Table is :
CREATE TABLE [dbo].[TIMESHEET](
[TIMESHEET_ID] [int] IDENTITY(1,1) NOT NULL,
[EMPLOYEE_ID] [varchar](25) NOT NULL,
[WEEK_START_DATE] [datetime] NOT NULL,
[WEEK_END_DATE] [datetime] NOT NULL,
[TIMESHEET_STATUS] [varchar](25) NOT NULL,
[REMARKS] [varchar](250) NULL
)
CREATE TABLE [dbo].[TIMESHEET_DETAIL](
[TIMESHEET_ID] [int] NOT NULL,
[DATE] [datetime] NOT NULL,
[PROJECT_ID] [varchar](25) NOT NULL,
[TASK_ID] [varchar](25) NOT NULL,
[TIME_IN] [datetime] NULL,
[TIME_OUT] [datetime] NULL,
[HOURS] [real] NOT NULL,
[REMARKS] [varchar](250) NULL
)
Just a brief explanation on the Tables.
The TIMESHEET table sample entries are listed below :
TIMESHEET_ID EMPLOYEE_ID WEEK_START_DATE WEEK_END_DATE TIMESHEET_STATUS REMARKS
1 EMP102 4/28/2013 5/4/2013 Open NULL
2 EMP001 4/28/2013 5/4/2013 Open NULL
The TIMESHEET_DETAIL table sample entries are listed below :
TIMESHEET_ID DATE PROJECT_ID TASK_ID START_TIME END_TIME NUM_HOURS REMARKS
2 5/2/2013 PRJ45 TASKA01 NULL NULL 3.2 NULL
2 5/4/2013 PRJ45 TASKA01 NULL NULL 2.2 NULL
2 5/4/2013 PRJ45 TASKB01 NULL NULL 1.6 NULL
2 5/4/2013 PRJ45 TASKE01 NULL NULL 1 NULL
1 5/3/2013 PRJ45 TASKA01 NULL NULL 2.5 NULL
1 5/3/2013 PRJ45 TASKB01 NULL NULL 0.5 NULL
1 5/4/2013 PRJ45 TASKA01 NULL NULL 1.5 NULL
1 5/4/2013 PRJ45 TASKB01 NULL NULL 0.5 NULL
1 5/4/2013 PRJ45 TASKC01 NULL NULL 2.5 NULL
1 5/4/2013 PRJ45 TASKD01 NULL NULL 3 NULL
The TIMESHEET table is the parent table and the TIMESHEET_DETAIL table is the child table. The TIMESHEET table will have one entry per week for each employee and the status will be Open, Pending for Approval, Approved, Rejected etc. The TIMESHEET_DETAIL will have details about each and every activity spent during that week and the number of hours spent on each of those activities.
My question is regarding the PRIMARY KEY for the TIMESHEET table and the TIMESHEET_DETAIL table. Right now there are 2 options for the PRIMARY KEY for the TIMESHEET table.
Option 1
Choose an auto-generated PRIMARY KEY. We have chosen this approach currently. TIMESHEET_ID is an auto-generated INT type PRIMARY KEY.
Option 2
We do not need the TIMESHEET_ID. The EMPLOYEE_ID together with the WEEK_START_DATE and WEEK_END_DATE can uniquely identify any row in the TIMESHEET table. But I feel it does not meet the criteria of being simple.
Which option is better for the TIMESHEET table and why ?
For the TIMESHEET_DETAIL table the composite PRIMARY KEY currently consists of
( TIMESHEET_ID, DATE, PROJECT_ID, TASK_ID )
. If we do not have the auto-generated PRIMARY KEY in the TIMESHEET table then we will only be having ( DATE, PROJECT_ID, TASK_ID )
as the
PRIMARY KEY for the TIMESHEET_DETAIL table.
Is there any better alternatives ?