sql >> Database teknologi >  >> RDS >> Mysql

Hent tabelmetadata i MySQL

For MySQL:

1) få metadata for tabel/felter

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;

ELLER

show fields from 'table_name' 

2) få Foregn Keys refereret tabel

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

3) få indekser (primære og udenlandske) for en tabel

show keys from `table_name`

5) få alle indekser og refereret tabel

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

ELLER

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

6) få GEMMEDE PROCEDURER

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

7) få TRIGGERS

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

8) få BEGIVENHEDER

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

9) få VISNINGER

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


  1. Kunne ikke indlæse JDBC-driverklassen [com.mysql.jdbc.Driver]

  2. Opdeling af streng i flere rækker i Oracle

  3. Langt heltal transformeres, når det indsættes i kortere kolonne, ikke afkortet. Hvorfor? Hvad er formlen?

  4. Postgres:Distinkt, men kun for én kolonne