SQL-Abfrage zur Datenbankstruktur:
WITH TabelleMitKommentar AS (
SELECT
t.TABLE_NAME,
t.TABLE_COMMENT
FROM
information_schema.TABLES t
WHERE
t.TABLE_SCHEMA = 'edpdb'
)
SELECT
CASE WHEN c.ORDINAL_POSITION = 1 THEN tmc.TABLE_COMMENT ELSE c.COLUMN_COMMENT END AS Kommentar,
tmc.TABLE_NAME,
c.COLUMN_NAME,
c.DATA_TYPE
FROM
information_schema.TABLES t
INNER JOIN information_schema.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME
INNER JOIN TabelleMitKommentar tmc ON t.TABLE_NAME = tmc.TABLE_NAME
WHERE
t.TABLE_SCHEMA = 'edpdb'
ORDER BY
t.TABLE_NAME, c.ORDINAL_POSITION;