CREATE TABLE [RECHTSPERSOON] (
    [RECHTSPERSOON_ID] INT PRIMARY KEY,
    [ADRESBINNENLAND] VARCHAR(255),
    [ADRESBUITENLAND] VARCHAR(255),
    [ADRESCORRESPONDENTIE] VARCHAR(100),
    [EMAILADRES] VARCHAR(80),
    [FAXNUMMER] VARCHAR(20),
    [IDENTIFICATIE] VARCHAR(255),
    [KVKNUMMER] VARCHAR(20),
    [NAAM] VARCHAR(200),
    [RECHTSVORM] VARCHAR(100),
    [REKENINGNUMMER] VARCHAR(255),
    [TELEFOONNUMMER] VARCHAR(20)
);

CREATE TABLE [PACHTER] (
    [RECHTSPERSOON_ID] INT PRIMARY KEY
);

CREATE TABLE [HUURDER] (
    [RECHTSPERSOON_ID] INT PRIMARY KEY
);

CREATE TABLE [EIGENAAR] (
    [RECHTSPERSOON_ID] INT PRIMARY KEY
);

CREATE TABLE [LEVERANCIER] (
    [RECHTSPERSOON_ID] INT PRIMARY KEY,
    [NAAM] VARCHAR(200),
    [NUMMER] VARCHAR(255)
);

CREATE TABLE [KP_PCHTR_RCHTSPRSN] (
    [KP_PCHTR_RCHTSPRSN_ID] INT PRIMARY KEY,
    [PACHTER_ID] INT,
    [RECHTSPERSOON_ID] INT
);

CREATE TABLE [KP_HRDR_RCHTSPRSN] (
    [KP_HRDR_RCHTSPRSN_ID] INT PRIMARY KEY,
    [HUURDER_ID] INT,
    [RECHTSPERSOON_ID] INT
);

CREATE TABLE [KP_EGNR_RCHTSPRSN] (
    [KP_EGNR_RCHTSPRSN_ID] INT PRIMARY KEY,
    [EIGENAAR_ID] INT,
    [RECHTSPERSOON_ID] INT
);

CREATE TABLE [KP_LVRNCR_RCHTSPRSN] (
    [KP_LVRNCR_RCHTSPRSN_ID] INT PRIMARY KEY,
    [LEVERANCIER_ID] INT,
    [RECHTSPERSOON_ID] INT
);

ALTER TABLE [EIGENAAR] ADD CONSTRAINT FK_EIGENAAR_GEN_RECHTSPERSOON FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- Generalization to RECHTSPERSOON

ALTER TABLE [HUURDER] ADD CONSTRAINT FK_HUURDER_GEN_RECHTSPERSOON FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- Generalization to RECHTSPERSOON

ALTER TABLE [PACHTER] ADD CONSTRAINT FK_PACHTER_GEN_RECHTSPERSOON FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- Generalization to RECHTSPERSOON

ALTER TABLE [LEVERANCIER] ADD CONSTRAINT FK_LEVERANCIER_GEN_RECHTSPERSOON FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- Generalization to RECHTSPERSOON

ALTER TABLE [KP_LVRNCR_RCHTSPRSN] ADD CONSTRAINT FK_KP_LVRNCR_RCHTSPRSN_1 FOREIGN KEY ([LEVERANCIER_ID]) REFERENCES [LEVERANCIER] ([RECHTSPERSOON_ID]);
-- LEVERANCIER (many-to-many junction, Connector_ID: 390)

ALTER TABLE [KP_LVRNCR_RCHTSPRSN] ADD CONSTRAINT FK_KP_LVRNCR_RCHTSPRSN_2 FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- RECHTSPERSOON (many-to-many junction, Connector_ID: 390)

ALTER TABLE [KP_PCHTR_RCHTSPRSN] ADD CONSTRAINT FK_KP_PCHTR_RCHTSPRSN_1 FOREIGN KEY ([PACHTER_ID]) REFERENCES [PACHTER] ([RECHTSPERSOON_ID]);
-- PACHTER (many-to-many junction, Connector_ID: 554)

ALTER TABLE [KP_PCHTR_RCHTSPRSN] ADD CONSTRAINT FK_KP_PCHTR_RCHTSPRSN_2 FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- RECHTSPERSOON (many-to-many junction, Connector_ID: 554)

ALTER TABLE [KP_HRDR_RCHTSPRSN] ADD CONSTRAINT FK_KP_HRDR_RCHTSPRSN_1 FOREIGN KEY ([HUURDER_ID]) REFERENCES [HUURDER] ([RECHTSPERSOON_ID]);
-- HUURDER (many-to-many junction, Connector_ID: 574)

ALTER TABLE [KP_HRDR_RCHTSPRSN] ADD CONSTRAINT FK_KP_HRDR_RCHTSPRSN_2 FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- RECHTSPERSOON (many-to-many junction, Connector_ID: 574)

ALTER TABLE [KP_EGNR_RCHTSPRSN] ADD CONSTRAINT FK_KP_EGNR_RCHTSPRSN_1 FOREIGN KEY ([EIGENAAR_ID]) REFERENCES [EIGENAAR] ([RECHTSPERSOON_ID]);
-- EIGENAAR (many-to-many junction, Connector_ID: 577)

ALTER TABLE [KP_EGNR_RCHTSPRSN] ADD CONSTRAINT FK_KP_EGNR_RCHTSPRSN_2 FOREIGN KEY ([RECHTSPERSOON_ID]) REFERENCES [RECHTSPERSOON] ([RECHTSPERSOON_ID]);
-- RECHTSPERSOON (many-to-many junction, Connector_ID: 577)

