CREATE TABLE [dbo].[Transaction] (
	[Id]					INT           IDENTITY (1, 1) NOT NULL,
	[ProfileId]				INT           NOT NULL,
	[ProfileTypeId]			INT           NOT NULL,
	[TransactionDate]		DATETIME      NOT NULL DEFAULT GETDATE(),
	[Description]			NVARCHAR (250) NOT NULL,
	[Reference]				NVARCHAR (70) NOT NULL,
	[TransactionTypeId]		INT NOT NULL,
	[Amount]				FLOAT (53)    NOT NULL,
	[TransactionStatusId]	INT NOT NULL, 
	[LoanId]				INT NULL, 
	[LoanRequestId]			INT NULL, 
	[LoanRepaymentId]		INT NULL, 
	CONSTRAINT [PK_Transaction] PRIMARY KEY CLUSTERED ([Id] ASC),
	CONSTRAINT [FK_Transaction_Profile] FOREIGN KEY ([ProfileId]) REFERENCES [dbo].[Profile] ([Id]),
	CONSTRAINT [FK_Transaction_ProfileType] FOREIGN KEY ([ProfileTypeId]) REFERENCES [dbo].[ProfileType] ([Id]),
	CONSTRAINT [FK_Transaction_TransactionType] FOREIGN KEY ([TransactionTypeId]) REFERENCES [dbo].[TransactionType] ([Id]),
	CONSTRAINT [FK_Transaction_TransactionStatus] FOREIGN KEY ([TransactionStatusId]) REFERENCES [dbo].[TransactionStatus] ([Id]), 
	CONSTRAINT [FK_Transaction_Loan] FOREIGN KEY ([LoanId]) REFERENCES[dbo].[Loan]([Id]), 
	CONSTRAINT [FK_Transaction_LoanRequest] FOREIGN KEY ([LoanRequestId]) REFERENCES [LoanRequest]([Id]),
	CONSTRAINT [FK_Transaction_Repayment] FOREIGN KEY ([LoanRepaymentId]) REFERENCES [LoanRepayment]([Id])

);

