Wednesday, October 27, 2010

Quick Table Query

Working with clients, sometime I have to deal wih more than 300
tables within a schema. In order to identify tables, views,
table size, alphabetical ordering of tables, engines etc.
Information Schema is the best place to look for detailed information.
Quick Alternatives:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.2.2-MariaDB-gamma Source distribution

This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use sakila;
Database changed
MariaDB [sakila]> show full tables;
+----------------------------+------------+
| Tables_in_sakila           | Table_type |
+----------------------------+------------+
| actor                      | BASE TABLE |
| actor_info                 | VIEW       |
| address                    | BASE TABLE |
| category                   | BASE TABLE |
| city                       | BASE TABLE |
| country                    | BASE TABLE |
| customer                   | BASE TABLE |
| customer_list              | VIEW       |
| film                       | BASE TABLE |
| film_actor                 | BASE TABLE |
| film_category              | BASE TABLE |
| film_list                  | VIEW       |
| film_text                  | BASE TABLE |
| inventory                  | BASE TABLE |
| jk                         | BASE TABLE |
| language                   | BASE TABLE |
| nicer_but_slower_film_list | VIEW       |
| payment                    | BASE TABLE |
| rental                     | BASE TABLE |
| sales_by_film_category     | VIEW       |
| sales_by_store             | VIEW       |
| staff                      | BASE TABLE |
| staff_list                 | VIEW       |
| store                      | BASE TABLE |
+----------------------------+------------+
24 rows in set (0.00 sec)

MariaDB [sakila]> show full tables where table_type='base table';
+------------------+------------+
| Tables_in_sakila | Table_type |
+------------------+------------+
| actor            | BASE TABLE |
| address          | BASE TABLE |
| category         | BASE TABLE |
| city             | BASE TABLE |
| country          | BASE TABLE |
| customer         | BASE TABLE |
| film             | BASE TABLE |
| film_actor       | BASE TABLE |
| film_category    | BASE TABLE |
| film_text        | BASE TABLE |
| inventory        | BASE TABLE |
| jk               | BASE TABLE |
| language         | BASE TABLE |
| payment          | BASE TABLE |
| rental           | BASE TABLE |
| staff            | BASE TABLE |
| store            | BASE TABLE |
+------------------+------------+
17 rows in set (0.01 sec)


MariaDB [sakila]> show full tables where table_type='view';
+----------------------------+------------+
| Tables_in_sakila           | Table_type |
+----------------------------+------------+
| actor_info                 | VIEW       |
| customer_list              | VIEW       |
| film_list                  | VIEW       |
| nicer_but_slower_film_list | VIEW       |
| sales_by_film_category     | VIEW       |
| sales_by_store             | VIEW       |
| staff_list                 | VIEW       |
+----------------------------+------------+
7 rows in set (0.01 sec)

MariaDB [sakila]> show full tables where tables_in_sakila like 'film%';
+------------------+------------+
| Tables_in_sakila | Table_type |
+------------------+------------+
| film             | BASE TABLE |
| film_actor       | BASE TABLE |
| film_category    | BASE TABLE |
| film_list        | VIEW       |
| film_text        | BASE TABLE |
+------------------+------------+
5 rows in set (0.00 sec)

MariaDB [sakila]> show table status where name='actor' and engine='innodb' \G
*************************** 1. row ***************************
         Name: actor
       Engine: InnoDB
      Version: 10
   Row_format: Compact
         Rows: 200
Avg_row_length: 81
  Data_length: 16384
Max_data_length: 0
 Index_length: 16384
    Data_free: 5242880
Auto_increment: 201
  Create_time: 2010-09-29 19:55:46
  Update_time: NULL
   Check_time: NULL
    Collation: utf8_general_ci
     Checksum: NULL
Create_options:
      Comment:
1 row in set (0.00 sec)



This is my first post.

Hope you all will enjoy!!!