CREATE TABLE [PRIMAIR_INKOMSTENCOMPONENT] (
    [PRIMAIR_INKOMSTENCOMPONENT_ID] INT PRIMARY KEY
);

CREATE TABLE [CLIENT] (
    [CLIENT_ID] INT PRIMARY KEY,
    [CODE] VARCHAR(80),
    [GEZAGSDRAGERGEKEND] BIT,
    [JURIDISCHESTATUS] VARCHAR(80),
    [WETTELIJKEVERTEGENWOORDIGING] VARCHAR(80)
);

CREATE TABLE [PROFIEL] (
    [PROFIEL_ID] INT PRIMARY KEY,
    [DATUMAANVANGPROFIEL] DATE,
    [DATUMEINDEPROFIEL] DATE,
    [HEEFT_CLIENT_ID] INT,
    [PROFIELTYPE] VARCHAR(200)
);

CREATE TABLE [VERMOGENSCOMPONENT] (
    [VERMOGENSCOMPONENT_ID] INT PRIMARY KEY,
    [BEVAT_PROFIEL_ID] INT,
    [CODE_SOORT_VERMOGENSCOMPONENT] VARCHAR(255),
    [DATUM_VASTSTELLING_VERMOGENCOMPONENT] DATE,
    [IDENTIFICATIE] VARCHAR(255),
    [NOG_AAN_TE_SPREKEN_VERMOGEN] VARCHAR(255),
    [VRIJ_TE_LATEN_VERMOGEN] VARCHAR(255)
);

CREATE TABLE [INKOMSTENVERHOUDING] (
    [INKOMSTENVERHOUDING_ID] INT PRIMARY KEY,
    [BEVAT_PROFIEL_ID] INT,
    [CATEGORIE_INKOMSTEN] VARCHAR(255),
    [INKOMSTENVERHOUDING_BEVAT_PRIMAIR_INKOMSTENCOMPONENT_PRIMAIR_INKOMSTENCOMPONENT_ID] INT,
    [PERIODE_EINDDATUM] DATE,
    [PERIODE_STARTDATUM] DATE
);

CREATE TABLE [BANKREKENING] (
    [VERMOGENSCOMPONENT_ID] INT PRIMARY KEY,
    [BANKREKENINGNUMMER] VARCHAR(255),
    [BEZIT_CLIENT_ID] INT,
    [BRONTYPE] VARCHAR(255),
    [DATUM_AANVANG_BANKREKENING] DATE,
    [DATUM_EINDE_BANKREKENING] DATE,
    [IBAN] VARCHAR(255),
    [REKENINGTYPE] VARCHAR(255),
    [TENAAMSTELLING] VARCHAR(255),
    [VOORKEUR_BANKREKENING] BIT
);

CREATE TABLE [KP_BNKRKNNG_VRMGNSCMPNNT] (
    [KP_BNKRKNNG_VRMGNSCMPNNT_ID] INT PRIMARY KEY,
    [BANKREKENING_ID] INT,
    [VERMOGENSCOMPONENT_ID] INT
);

ALTER TABLE [BANKREKENING] ADD CONSTRAINT FK_BANKREKENING_GEN_VERMOGENSCOMPONENT FOREIGN KEY ([VERMOGENSCOMPONENT_ID]) REFERENCES [VERMOGENSCOMPONENT] ([VERMOGENSCOMPONENT_ID]);
-- Generalization to VERMOGENSCOMPONENT

ALTER TABLE [KP_BNKRKNNG_VRMGNSCMPNNT] ADD CONSTRAINT FK_KP_BNKRKNNG_VRMGNSCMPNNT_1 FOREIGN KEY ([BANKREKENING_ID]) REFERENCES [BANKREKENING] ([VERMOGENSCOMPONENT_ID]);
-- BANKREKENING (many-to-many junction, Connector_ID: 871)

ALTER TABLE [KP_BNKRKNNG_VRMGNSCMPNNT] ADD CONSTRAINT FK_KP_BNKRKNNG_VRMGNSCMPNNT_2 FOREIGN KEY ([VERMOGENSCOMPONENT_ID]) REFERENCES [VERMOGENSCOMPONENT] ([VERMOGENSCOMPONENT_ID]);
-- VERMOGENSCOMPONENT (many-to-many junction, Connector_ID: 871)

ALTER TABLE [INKOMSTENVERHOUDING] ADD CONSTRAINT FK_INKOMSTENVERHOUDING_INKOMSTENVERHOUDING_BEVAT_PRIMAIR_INKOMSTENCOMPONENT FOREIGN KEY ([INKOMSTENVERHOUDING_BEVAT_PRIMAIR_INKOMSTENCOMPONENT_PRIMAIR_INKOMSTENCOMPONENT_ID]) REFERENCES [PRIMAIR_INKOMSTENCOMPONENT] ([PRIMAIR_INKOMSTENCOMPONENT_ID]);
-- INKOMSTENVERHOUDING_BEVAT_PRIMAIR_INKOMSTENCOMPONENT (1..* to 0..1, Connector_ID: 901)

ALTER TABLE [VERMOGENSCOMPONENT] ADD CONSTRAINT FK_VERMOGENSCOMPONENT_BEVAT FOREIGN KEY ([BEVAT_PROFIEL_ID]) REFERENCES [PROFIEL] ([PROFIEL_ID]);
-- BEVAT (1..2 to 0..*, Connector_ID: 924)

ALTER TABLE [INKOMSTENVERHOUDING] ADD CONSTRAINT FK_INKOMSTENVERHOUDING_BEVAT FOREIGN KEY ([BEVAT_PROFIEL_ID]) REFERENCES [PROFIEL] ([PROFIEL_ID]);
-- BEVAT (1 to 0..*, Connector_ID: 925)

ALTER TABLE [BANKREKENING] ADD CONSTRAINT FK_BANKREKENING_BEZIT FOREIGN KEY ([BEZIT_CLIENT_ID]) REFERENCES [CLIENT] ([CLIENT_ID]);
-- BEZIT (1..2 to 0..*, Connector_ID: 945)

ALTER TABLE [PROFIEL] ADD CONSTRAINT FK_PROFIEL_HEEFT FOREIGN KEY ([HEEFT_CLIENT_ID]) REFERENCES [CLIENT] ([CLIENT_ID]);
-- HEEFT (1 to 1..*, Connector_ID: 947)

