Is it possible to select from show tables
in MySQL?
SELECT * FROM (SHOW TABLES) AS `my_tables`
Something along these lines, th
in MySql 5.1 you can try
show tables like 'user%';
output:
mysql> show tables like 'user%';
+----------------------------+
| Tables_in_test (user%) |
+----------------------------+
| user |
| user_password |
+----------------------------+
2 rows in set (0.00 sec)
SELECT * FROM INFORMATION_SCHEMA.TABLES
That should be a good start. For more, check INFORMATION_SCHEMA Tables.
SELECT column_comment FROM information_schema.columns WHERE table_name = 'myTable' AND column_name = 'myColumnName'
This will return the comment on: myTable.myColumnName
Not that I know of, unless you select from INFORMATION_SCHEMA
, as others have mentioned.
However, the SHOW
command is pretty flexible,
E.g.:
SHOW tables like '%s%'
Yes, SELECT from table_schema could be very usefull for system administration. If you have lot of servers, databases, tables... sometimes you need to DROP or UPDATE bunch of elements. For example to create query for DROP all tables with prefix name "wp_old_...":
SELECT concat('DROP TABLE ', table_name, ';') FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = '*name_of_your_database*'
AND table_name LIKE 'wp_old_%';
To count:
SELECT COUNT(*) as total FROM (SELECT TABLE_NAME as tab, TABLES.* FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='database_name' GROUP BY tab) tables;
To list:
SELECT TABLE_NAME as table, TABLES.* FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='database_name' GROUP BY table;