sql >> Database >  >> RDS >> Mysql

Tabelmetadata ophalen in MySQL

Voor MySQL:

1) krijg tabel/velden metadata

SELECT table_schema, table_name, column_name, ordinal_position, data_type, 
       numeric_precision, column_type, column_default, is_nullable, column_comment 
  FROM information_schema.columns 
  WHERE (table_schema='schema_name' and table_name = 'table_name')
  order by ordinal_position;

OF

show fields from 'table_name' 

2) haal Foregn Keys-referentietabel op

SELECT `REFERENCED_TABLE_NAME` 
   FROM `information_schema`.`KEY_COLUMN_USAGE`
   WHERE
       `TABLE_NAME` = 'table_name' AND
       `COLUMN_NAME` = 'Column_Name'

3) verkrijg indexen (primair en buitenlands) voor een tabel

show keys from `table_name`

5) haal Alle indexen en gerefereerde tabel op

SELECT *
  FROM `KEY_COLUMN_USAGE`
  WHERE
      `TABLE_NAME` = 'table_name' AND
      `TABLE_SCHEMA` = 'schema_name'

OF

SELECT *
  FROM `REFERENTIAL_CONSTRAINTS`
  WHERE
      `TABLE_NAME` = 'table_name' AND
      `CONSTRAINT_SCHEMA` = 'schema_name'

6) OPGESLAGEN PROCEDURES ophalen

SELECT * 
  FROM `ROUTINES`
  WHERE
     `ROUTINE_SCHEMA` = 'schema_name'

7) TRIGGERS ophalen

SELECT * 
  FROM `TRIGGERS`
  WHERE 
     `TRIGGER_SCHEMA` = 'schema_name'

8) ontvang EVENEMENTEN

SELECT * 
  FROM `EVENTS`
  WHERE 
     `EVENT_SCHEMA` = 'schema_name'

9) KRIJG VIEWS

SELECT *
  FROM `VIEWS`
  WHERE
      `TABLE_NAME` = 'table_name' AND
      `TABLE_SCHEMA` = 'schema_name'


  1. Getallen opmaken met komma's in PostgreSQL

  2. Hoe de prestaties voor datetime-filtering in SQL Server te verbeteren?

  3. 6 manieren om dubbele rijen in Oracle te selecteren

  4. Een productieklaar MySQL- of MariaDB Galera-cluster implementeren met ClusterControl