SHOW TABLES är MariaDB:s administrativa genväg för att se vad en databas innehåller. Den listar de icke-TEMPORARY-tabellerna, sekvenserna och vyerna, och den accepterar ett par valfria modifierare för filtrering och extra detalj.
Syntax
SHOW [FULL] TABLES [FROM db_name] [LIKE 'pattern' | WHERE expr]
Grundläggande exempel
SHOW TABLES;
Resultat:
+------------------------+ | Tables_in_krankykranes | +------------------------+ | Customers | | Dogs | | Gameshow | | OrderItems | | Orders | | PetShow | | Pets | | Products | | Vendors | | t1 | +------------------------+
Allt som listas finns i den aktuella databasen, vilket i den här sessionen är KrankyKranes. Använd FROM db_name för att titta någon annanstans utan att först byta databas.
Visa objekttypen
Modifieraren FULL lägger till en andra kolumn som skiljer bastabeller från vyer:
USE sakila; SHOW FULL TABLES;
Resultat:
+----------------------------+------------+ | Tables_in_sakila | Table_type | +----------------------------+------------+ | actor | BASE TABLE | | 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 | | 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 | +----------------------------+------------+
Exemplet Sakila skickar poängen hem: flera av dessa poster är vyer snarare än tabeller.
Satsen LIKE
På egen hand filtrerar LIKE efter namnmonster:
SHOW FULL TABLES LIKE 'f%';
Resultat:
+-----------------------+------------+ | Tables_in_sakila (f%) | Table_type | +-----------------------+------------+ | film | BASE TABLE | | film_actor | BASE TABLE | | film_category | BASE TABLE | | film_list | VIEW | | film_text | BASE TABLE | +-----------------------+------------+
Satsen WHERE
WHERE är mer flexibel, eftersom du kan testa valfri kolumn:
SHOW FULL TABLES WHERE Table_type = 'BASE TABLE';
Resultat:
+------------------+------------+ | 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 | | language | BASE TABLE | | payment | BASE TABLE | | rental | BASE TABLE | | staff | BASE TABLE | | store | BASE TABLE | +------------------+------------+
Den första kolumnen följer namngivningskonventionen Tables_in_dbname, och du kan filtrera på den också:
SHOW FULL TABLES WHERE Tables_in_sakila = 'customer';
Resultat:
+------------------+------------+ | Tables_in_sakila | Table_type | +------------------+------------+ | customer | BASE TABLE | +------------------+------------+