ALTER TABLE LD0P0C SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0C WHERE AEVERKNR NOT IN (SELECT AEVERKNR FROM LD0P0C)
GO
ALTER TABLE LD0P0C SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0C01 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0C01 WHERE NOT EXISTS (SELECT * FROM LD0P0C01 C01
	WHERE C01.AEVERKNR=LD0L0C01.AEVERKNR AND C01.PNR=LD0L0C01.PNR)
GO
ALTER TABLE LD0P0C01 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0C20 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0C20 WHERE NOT EXISTS (SELECT * FROM LD0P0C20 C20
	WHERE C20.INSNR=LD0L0C20.INSNR)
GO
ALTER TABLE LD0P0C20 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0C21 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0C21 WHERE NOT EXISTS (SELECT * FROM LD0P0C21 C21
	WHERE C21.INSNR=LD0L0C21.INSNR AND C21.PNR=LD0L0C21.PNR)
GO
ALTER TABLE LD0P0C21 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0D SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0D WHERE NOT EXISTS (SELECT * FROM LD0P0D D
	WHERE D.BERAKNR=LD0L0D.BERAKNR)
GO
ALTER TABLE LD0P0D SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0D01 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0D01 WHERE NOT EXISTS (SELECT * FROM LD0P0D01 D01
	WHERE D01.BERAKNR=LD0L0D01.BERAKNR AND D01.PNR=LD0L0D01.PNR)
GO
ALTER TABLE LD0P0D01 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0D02 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0D02 WHERE NOT EXISTS (SELECT * FROM LD0P0D02 D02
	WHERE D02.BERAKNR=LD0L0D02.BERAKNR AND D02.INKNR=LD0L0D02.INKNR)
GO
ALTER TABLE LD0P0D02 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0D03 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0D03 WHERE NOT EXISTS (SELECT * FROM LD0P0D03 D03
	WHERE D03.BERAKNR=LD0L0D03.BERAKNR AND D03.UTGNR=LD0L0D03.UTGNR)
GO
ALTER TABLE LD0P0D03 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0D04 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0D04 WHERE NOT EXISTS (SELECT * FROM LD0P0D04 D04
	WHERE D04.BERAKNR=LD0L0D04.BERAKNR AND D04.SPECNR=LD0L0D04.SPECNR)
GO
ALTER TABLE LD0P0D04 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0E SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0E WHERE NOT EXISTS (SELECT * FROM LD0P0E E
	WHERE E.BESLUTNR=LD0L0E.BESLUTNR)
GO
ALTER TABLE LD0P0E SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0E01 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0E01 WHERE NOT EXISTS (SELECT * FROM LD0P0E01 E01
	WHERE E01.BESLUTNR=LD0L0E01.BESLUTNR and E01.PNR=LD0L0E01.PNR)
GO
ALTER TABLE LD0P0E01 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0F SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0F WHERE NOT EXISTS (SELECT * FROM LD0P0F F
	WHERE F.BETALNR=LD0L0F.BETALNR)
GO
ALTER TABLE LD0P0F SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0F01 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0F01 WHERE NOT EXISTS (SELECT * FROM LD0P0F01 F01
	WHERE F01.BETALNR=LD0L0F01.BETALNR AND F01.PNR=LD0L0F01.PNR)
GO
ALTER TABLE LD0P0F01 SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0H SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0H WHERE NOT EXISTS (SELECT * FROM LD0P0H H
	WHERE H.AKTUALNR=LD0L0H.AKTUALNR)
GO
ALTER TABLE LD0P0H SET (SYSTEM_VERSIONING = ON)
GO

ALTER TABLE LD0P0N70 SET (SYSTEM_VERSIONING = OFF)
GO
DELETE FROM LD0L0N70 WHERE NOT EXISTS (SELECT * FROM LD0P0N70 N70
	WHERE N70.RESTILLDNR=LD0L0N70.RESTILLDNR)
GO
ALTER TABLE LD0P0N70 SET (SYSTEM_VERSIONING = ON)
GO