การ Query จาก information_schema.tables
กรองเฉพาะตารางที่มีข้อมูล (table_rows >= 1) ในฐานข้อมูลที่ต้องการ
รูปแบบคำสั่ง
SELECT table_type, table_name, table_schema FROM information_schema.tables WHERE table_rows >= 1 AND table_schema = 'yourDatabaseName';
ตัวอย่างกับฐานข้อมูล 'test'
mysql> SELECT table_type, table_name, table_schema
-> FROM information_schema.tables
-> WHERE table_rows >= 1 AND table_schema = 'test';
ผลลัพธ์ตัวอย่าง (บางส่วน)
+------------+------------------------------+--------------+ | TABLE_TYPE | TABLE_NAME | TABLE_SCHEMA | +------------+------------------------------+--------------+ | BASE TABLE | add30minutesdemo | test | | BASE TABLE | addoneday | test | | BASE TABLE | agecalculatesdemo | test | | BASE TABLE | aliasdemo | test | | ... (รวม 80 ตาราง) | | +------------+------------------------------+--------------+ 80 rows in set (0.00 sec)
คำอธิบาย:
TABLE_TYPE = 'BASE TABLE'แสดงว่าเป็นตารางจริง (ไม่ใช่ View)table_rows >= 1กรองเฉพาะตารางที่มีข้อมูลอย่างน้อย 1 แถว- ค่า table_rows เป็นค่าประมาณการสำหรับ InnoDB
คำสั่งนับแถวที่แน่นอนสำหรับตารางเฉพาะ:
SELECT COUNT(*) FROM yourTableName;