[Sample Database Design][1]
[1]: https://i.stack.imgur.com/2vxEb.png
-- table "dbo.Month"
CREATE TABLE dbo.Month (
Id int NOT NULL,
Name nvarchar(50) NOT NULL,
CONSTRAINT PK_Month PRIMARY KEY CLUSTERED (Id)
)
-- table IncomeType"
CREATE TABLE dbo.IncomeType (
Id int NOT NULL,
Name nvarchar(50) NOT NULL,
CONSTRAINT PK_IncomeType PRIMARY KEY CLUSTERED (Id)
)
-- table "FinancialYear"
CREATE TABLE dbo.FinancialYear (
Id int NOT NULL,
YearSpan nvarchar(50) NOT NULL,
CONSTRAINT PK_FinancialYear PRIMARY KEY CLUSTERED (Id)
)
-- table "Employee"
CREATE TABLE dbo.Employee (
Id int NOT NULL,
Name nvarchar(50) NOT NULL,
CONSTRAINT PK_Employee PRIMARY KEY CLUSTERED (Id)
)
-- table "Income"
CREATE TABLE dbo.Income (
Id int NOT NULL,
EmployeeId int NOT NULL,
TypeId int NOT NULL,
YearSpanId int NOT NULL,
MonthId int NOT NULL,
CONSTRAINT PK_Income PRIMARY KEY CLUSTERED (Id)
)
--Alter Each Table to add foreign key references
ALTER TABLE Income
ADD CONSTRAINT FK_Income_Employee FOREIGN KEY (EmployeeId) REFERENCES Employee (Id)
ALTER TABLE dbo.Income
ADD CONSTRAINT FK_Income_FinancialYear FOREIGN KEY (YearSpanId) REFERENCES dbo.FinancialYear (Id)
ALTER TABLE dbo.Income
ADD CONSTRAINT FK_Income_IncomeType FOREIGN KEY (TypeId) REFERENCES dbo.IncomeType (Id)
ALTER TABLE dbo.Income
ADD CONSTRAINT FK_Income_Month FOREIGN KEY (MonthId) REFERENCES dbo.Month (Id)
- EmployeeID will come from the Employee table
- Element will come from the income type table
- FinancialYear --from the financial year table
- MonthId from the months table
Now a simple join can help you get each value using the foreign key references