I MariaDB, SHOW TABLES er en administrativ erklæring, der viser den ikke-TEMPORARY tabeller, sekvenser og visninger i en given database.
Syntaks
Syntaksen ser sådan ud:
SHOW [FULL] TABLES [FROM db_name]
[LIKE 'pattern' | WHERE expr] Eksempel
Her er et eksempel til demonstration:
SHOW TABLES; Resultat:
+------------------------+ | Tables_in_krankykranes | +------------------------+ | Customers | | Dogs | | Gameshow | | OrderItems | | Orders | | PetShow | | Pets | | Products | | Vendors | | t1 | +------------------------+
Dette viser os tabellerne i den aktuelle database, som i dette tilfælde er KrankyKranes database.
Vis tabeltypen
Vi kan bruge FULL modifikator for at returnere tabeltypen:
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 | +----------------------------+------------+
Her skiftede jeg til Sakila databasen og kørte derefter SHOW FULL TABLES . Vi kan se, at nogle af de returnerede tabeller faktisk er visninger.
Som nævnt returnerer sætningen tabeller, sekvenser og visninger.
LIKE Klausul
LIKE klausul, hvis den findes alene, angiver, hvilke tabelnavne der skal matche:
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 | +-----------------------+------------+
WHERE Klausul
WHERE klausul kan bruges til at filtrere resultaterne baseret på et givet kriterium:
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 | +------------------+------------+
Vi kan også bruge WHERE klausul mod den første kolonne ved at bruge Tables_in_dbname konvention, hvor dbname er navnet på databasen:
SHOW FULL TABLES
WHERE Tables_in_sakila = 'customer'; Resultat:
+------------------+------------+ | Tables_in_sakila | Table_type | +------------------+------------+ | customer | BASE TABLE | +------------------+------------+