jesse1981
3/15/2018 - 12:22 AM

Database Structures | MySQL

SELECT	TABLE_NAME as source_table,
        COLUMN_NAME as source_column,
        CONSTRAINT_NAME as constraint_name,
        REFERENCED_TABLE_NAME as referenced_table,
        REFERENCED_COLUMN_NAME as referenced_column
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE (TABLE_NAME = :table AND COLUMN_NAME = :field ) OR
      (REFERENCED_TABLE_NAME = :table AND REFERENCED_COLUMN_NAME = :field)
SELECT DISTINCT
        column_name,
        data_type,
        CASE is_nullable
          WHEN 'YES' THEN 'NO'
          ELSE 'YES'
        END as required,
        EXTRA as extra,
        character_maximum_length,
        ordinal_position
FROM information_schema.columns
WHERE table_name = :table
SELECT table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'