INFORMATION_SCHEMA
-- Spalten suchen
SELECT table_schema, table_name, column_name, ordinal_position, data_type, character_maximum_length, numeric_precision, numeric_scale, column_type
FROM information_schema.columns
WHERE LOWER(column_name) LIKE '%%'
ORDER BY table_schema, table_name, column_name
;
-- Überhang
SELECT table_schema, table_name, engine, table_rows, avg_row_length, data_length, max_data_length, index_length, data_free
FROM information_schema.tables
WHERE data_free > 0
ORDER BY data_free DESC
;
-- Indizes
SELECT
table_schema, table_name, non_unique, index_name, seq_in_index, column_name, cardinality, nullable
FROM information_schema.statistics
WHERE
lower(table_schema) LIKE 'bdb%'
AND lower(table_name) LIKE '%'
AND lower(index_name) LIKE '%'
ORDER BY table_schema, table_name, index_name, seq_in_index
;
-- Fremdschlüssel
SELECT
table_schema
, table_name
, constraint_name
, column_name
, referenced_table_name
, referenced_column_name
FROM
information_schema.key_column_usage
WHERE
referenced_table_name IS NOT NULL
ORDER BY
table_schema
, table_name
, constraint_name
, column_name
, referenced_table_name
, referenced_column_name
;
--
USE 'mydb'
SELECT
CONCAT(table_name, '.', column_name) AS 'foreign key',
CONCAT(referenced_table_name, '.', referenced_column_name) AS 'references',
constraint_name AS 'constraint name'
FROM
information_schema.key_column_usage
WHERE
referenced_table_name IS NOT NULL
AND table_schema = DATABASE()
ORDER BY table_name, column_name, referenced_table_name, referenced_column_name
;
SELECT tc.table_name, tc.constraint_type, tc.constraint_name, kcu.referenced_table_name, kcu.referenced_column_name
FROM information_schema.table_constraints tc LEFT JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name
WHERE tc.constraint_type = 'FOREIGN KEY'
AND tc.table_schema = DATABASE()
ORDER BY tc.table_name, kcu.referenced_table_name
;
-- Storage Engines
SELECT table_schema, table_name, table_type, engine, version, row_format, table_rows, avg_row_length, data_length, index_length
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY Engine, table_schema, table_name
;