database design help please

  • Hi I am having some trouble on how to normalize some tricky tables.

    Basically it is a recurrence event table that can either be daily, weekly, monthly or yearly.

    I have made it so each recurrence row in the header table can have one id for either daily, weekly, monthly or yearly. This id corresponds to the appropriate table. Each table has different structures.

    So here is an example of what I have.

    Table: Recurrence

    Columns: RecurrenceId (PK), RecurrenceDailyId(FK), RecurrenceWeeklyId (FK),

    RecurrenceMonthlyId (FK), RecurrenceYearlyId (FK)

    Table: RecurrenceDailyId

    Columns: RecurrenceDailyId(PK), EveryDays, DayOfWeek etc

    Table: RecurrenceWeeklyId

    Columns: RecurrenceWeeklyId(PK), EveryWeeks, TimesAWeek etc

    etc

    What is the best way to create this structure so it is normalized? am I on the right path?

  • Nah, I'd say you're digging a bit of a hole. Instead how about something like

    Recurrence ... whatever columns are unique to the recurrence

    RecurrenceSchedule ... just a listing of each of the types, daily, monthly, etc., and any unique values to them

    RecurrenceScheduleType ... a join between the schedule and the recurrance. Probably make the primary key the two tables keys, but put a unique constraint on the Recurrence key in addition so that a recurrence can only have one type.

    The other method involves a lot of null values and joins to tables without data. This will ensure you always get data back.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply