Lệnh SHOW TABLES liệt kê tất cả bảng trong database hiện tại hoặc database chỉ định.
Cú pháp
SHOW TABLES [FROM ten_database];
Hoặc (tương đương):
SHOW TABLES IN ten_database;
Ví dụ minh họa
Xem bảng trong database hb_student_tracker:
SHOW TABLES FROM hb_student_tracker;
Kết quả (rút gọn)
| Tables_in_hb_student_tracker |
|---|
| demotable192 |
| demotable193 |
| ... |
| student |
(44 bảng trong ví dụ gốc)
Các biến thể hữu ích
1. Lọc tên bảng với LIKE
SHOW TABLES FROM hb_student_tracker LIKE 'demo%';
2. Xem thông tin chi tiết (MySQL 5.0+)
SHOW TABLE STATUS FROM hb_student_tracker;
Trả về: Engine, Rows, Data_length, Auto_increment, Create_time, Collation...
3. Từ INFORMATION_SCHEMA (linh hoạt hơn)
SELECT table_name, table_rows, engine, table_collation FROM information_schema.tables WHERE table_schema = 'hb_student_tracker';
Lưu ý
SHOW TABLESkhông hiển thị VIEW (dùngSHOW FULL TABLESđể phân biệt).- Quyền: Cần quyền
SHOW DATABASEShoặc quyền truy cập database đó. - Trong ứng dụng, dùng
information_schemađể query lập trình được (filter, join, order...).