How to query `information_schema`?

To query the information_schema database, you can use standard SQL SELECT statements. Here are a few examples:

  1. List all databases:

    SELECT SCHEMA_NAME FROM information_schema.SCHEMATA;
  2. List all tables in a specific database:

    SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'your_database_name';
  3. Get information about columns in a specific table:

    SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE 
    FROM information_schema.COLUMNS 
    WHERE TABLE_SCHEMA = 'your_database_name' AND TABLE_NAME = 'your_table_name';
  4. Get the number of tables in a specific database:

    SELECT COUNT(*) AS table_count 
    FROM information_schema.TABLES 
    WHERE TABLE_SCHEMA = 'your_database_name';

Replace your_database_name and your_table_name with the actual names of your database and table as needed.

0 Comments

no data
Be the first to share your comment!