I have an expense management system for monthly expenses. Expenses are of two types: one-time monthly expenses, and daily expenses for each day of month. I have created the following tables:
setupExpenses (ExpenseID, Title, IsDaily)
ExpenseMaster (ExpenseMasterID, Month, EmployeeID)
ExpenseDetails (ExpDetID, ExpenseMasterID, ExpenseID, Date, Amount)
ExpenseDetailsDaily(ID, ExpDetID, Date, Amount)
if isdaily
is true
in setupExpenses
then an entry is made in the 3rd table otherwise I have entries in the other two transaction tables. Any better suggesstion is appreciated. This design doesn't feel right to me.
Best Answer
Without knowing more about the business requirements, with the given structure you defined I would probably go with something like this:
Where
Expense.TypeId
is a foreign key constraint toExpenseType.Id
.ExpenseType
could contain rows for daily or monthly expenses. This is scalable, as if down the road you have the requirement for weekly expenses, or yearly expenses (etc.) then this normalization will benefit.Expense.EmployeeId
would be a foreign key constraint to your employee table, andExpense.DetId
sounds like it'd be a foreign key constraint to another table that I can't seem to translate from the column name. If it is just details for each expense, no reason not to just put it directly in theExpense
table (provided a 1:1 relationship between expense and expense details). I may be missing a few columns, but I'm sure you get the idea.