Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

แสดงชื่อตารางเฉพาะบางตารางด้วย LIKE ใน MySQL

คิวรี่ดูชื่อตารางจาก information_schema ด้วย LIKE

select table_name as `anyAliasName` from information_schema.tables where table_name like 'yourValue%';

ตัวอย่างค้นหาตารางขึ้นต้นด้วย DemoTable160_

mysql> select table_name as `DemoTable1600` 
    -> from information_schema.tables 
    -> where table_name like 'DemoTable160_%';

ผลลัพธ์

+---------------+ 
| DemoTable1600 | 
+---------------+ 
| demotable1600 | 
| demotable1601 | 
| demotable1602 | 
| demotable1603 | 
| demotable1604 | 
| demotable1605 | 
| demotable1606 | 
| demotable1607 | 
+---------------+ 
8 rows in set (0.01 sec)

ใช้งานได้กับ MySQL ทุกเวอร์ชัน ช่วยค้นหาตารางได้รวดเร็วโดยไม่ต้องใช้ SHOW TABLES