Berikut adalah empat cara untuk membuat daftar tampilan dalam database MariaDB menggunakan SQL atau baris perintah.
SHOW TABLES Perintah
SHOW TABLES perintah mencantumkan non-TEMPORARY tabel, urutan dan tampilan dalam database yang diberikan. Kita dapat menggunakan WHERE klausa untuk mempersempitnya menjadi hanya tampilan.
Kami juga dapat menggunakan FULL pengubah untuk mengembalikan kolom kedua yang menampilkan jenis:
SHOW FULL TABLES
WHERE Table_Type LIKE 'VIEW'; Hasil:
+--------------------+------------+ | Tables_in_pethouse | Table_type | +--------------------+------------+ | vownercount | VIEW | | vpetcount | VIEW | | vpetsowners | VIEW | | vpetstypes | VIEW | | vpettypecount | VIEW | +--------------------+------------+
Menghilangkan WHERE klausa mengembalikan semua jenis:
SHOW FULL TABLES; Hasil:
+--------------------+------------+ | Tables_in_pethouse | Table_type | +--------------------+------------+ | Owners | BASE TABLE | | PetTypes | BASE TABLE | | Pets | BASE TABLE | | vownercount | VIEW | | vpetcount | VIEW | | vpetsowners | VIEW | | vpetstypes | VIEW | | vpettypecount | VIEW | +--------------------+------------+
The SHOW TABLE STATUS Perintah
SHOW TABLE STATUS perintahnya mirip dengan SHOW TABLES perintah tetapi memberikan informasi yang lebih luas tentang masing-masing (non-TEMPORARY ) tabel.
Contoh:
SHOW TABLE STATUS; Hasil:
+---------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+------------------+-----------+ | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment | Max_index_length | Temporary | +---------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+------------------+-----------+ | Owners | InnoDB | 10 | Dynamic | 6 | 2730 | 16384 | 0 | 0 | 0 | NULL | 2021-03-30 09:10:36 | NULL | NULL | utf8mb4_general_ci | NULL | | | 0 | N | | PetTypes | InnoDB | 10 | Dynamic | 4 | 4096 | 16384 | 0 | 0 | 0 | NULL | 2021-03-30 09:10:36 | NULL | NULL | utf8mb4_general_ci | NULL | | | 0 | N | | Pets | InnoDB | 10 | Dynamic | 8 | 2048 | 16384 | 0 | 32768 | 0 | NULL | 2021-04-01 15:42:43 | NULL | NULL | utf8mb4_general_ci | NULL | | | 0 | N | | vownercount | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpetcount | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpetsowners | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpetstypes | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | | vpettypecount | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | VIEW | NULL | NULL | +---------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+------------------+-----------+
Itu juga menerima WHERE dan LIKE klausa jika Anda ingin mempersempit hasil.
information_schema.TABLES Tabel
Kami juga dapat menanyakan information_schema.TABLES tabel:
SELECT
TABLE_SCHEMA,
TABLE_NAME,
TABLE_TYPE
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA LIKE 'pethouse' AND TABLE_TYPE LIKE 'VIEW'; Hasil:
+--------------+---------------+------------+ | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | +--------------+---------------+------------+ | PetHouse | vpettypecount | VIEW | | PetHouse | vpetstypes | VIEW | | PetHouse | vownercount | VIEW | | PetHouse | vpetcount | VIEW | | PetHouse | vpetsowners | VIEW | +--------------+---------------+------------+
Menanyakan ini tanpa memfilter hasil dengan TABLE_SCHEMA mengembalikan tampilan dari semua database. Demikian pula, menanyakannya tanpa memfilter menurut TABLE_TYPE mengembalikan semua jenis tabel.
mariadb-show Klien
Cara lain untuk melakukannya adalah dengan mariadb-show kegunaan.
Untuk menggunakan opsi ini, buka jendela prompt/terminal baris perintah dan jalankan perintah berikut (menggantikan pethouse dengan database yang Anda minati):
mariadb-show pethouse; Hasil:
+---------------+ | Tables | +---------------+ | Owners | | PetTypes | | Pets | | vownercount | | vpetcount | | vpetsowners | | vpetstypes | | vpettypecount | +---------------+
Ini mengembalikan tampilan dan tabel.
Outputnya hanya menampilkan nama database, tabel, atau kolom yang Anda miliki beberapa hak istimewanya.
Jika tidak ada database yang diberikan maka semua database yang cocok akan ditampilkan. Jika tidak ada tabel yang diberikan, maka semua tabel yang cocok dalam database akan ditampilkan. Jika tidak ada kolom yang diberikan, maka semua kolom dan tipe kolom yang cocok dalam tabel akan ditampilkan.
Klien juga dapat dijalankan sebagai mysqlshow :
mysqlshow pethouse;
Utilitas ini menerima beberapa opsi, seperti --user (agar Anda dapat memberikan nama pengguna), --password (agar Anda dapat memasukkan kata sandi), dll.
Lihat dokumentasi MariaDB untuk daftar lengkap opsi.