-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
To generate a JSON output containing only the table names and their structures without the schema, you can use the following SQL query:
SELECT JSON_OBJECTAGG(
table_name,
JSON_OBJECT(
'structure', CREATE_TABLE
)
) AS tables_structure
FROM (
SELECT
table_name,
CONCAT(
'CREATE TABLE ', table_name, ' (',
GROUP_CONCAT(
CONCAT(column_name, ' ', column_type,
IF(is_nullable = 'NO', ' NOT NULL', ''),
IF(column_default IS NOT NULL, CONCAT(' DEFAULT ', column_default), ''),
IF(extra != '', CONCAT(' ', extra), '')
) SEPARATOR ', '
),
')'
) AS CREATE_TABLE
FROM information_schema.columns
WHERE table_schema = DATABASE()
GROUP BY table_name
) AS table_structures;This query will produce a JSON object where each key is a table name, and the value is another JSON object containing the table structure. You can run this query in your MySQL database to get a JSON representation of all table structures without the schema.
Metadata
Metadata
Assignees
Labels
No labels