[英]MySQL Query To Return, Schema_Name, Table_NAme, Count, Size_of_Table, Primary_Key and Auto_Increment_Key
I have another tough MySQL query that I am trying to work out. 我有另一个难以解决的MySQL查询,正在尝试解决。 I need a query that will return the following in a single command: 我需要一个查询,该查询将在单个命令中返回以下内容:
+----------+------------------------------+-----------+-------------+----------------+--------------------+
| Database | Table_Name | Count | Size | Primary-Key | Auto_Increment_Key |
+----------+------------------------------+-----------+-------------+----------------+--------------------+
| mydb | account_length | 2408 | 0.04 Mb | account_id | account_id |
| mydb | account_log | 1225 | 0.09 Mb | log_id | NULL |
I am still new to MySQL. 我还是MySQL的新手。 I have tried various queries against the information_schema, but have not been able to get one that returns the data I need. 我已经尝试过对information_schema进行各种查询,但是无法获得返回我所需数据的查询。
The query would simply get a table's row count, it's size in MB, it's primary-key column and it's auto_increment key column. 该查询将仅获得表的行数,大小(以MB为单位),主键列和auto_increment键列。
I appreciate any help. 感谢您的帮助。
Thanks 谢谢
Something like this will help you: 这样的事情将帮助您:
SELECT t.table_schema,
t.table_name,
Round(( t.data_length + t.index_length ) / 1048576, 2) AS sizemb,
c1.column_name AS primarycol,
c2.column_name AS
autoincrementcol
FROM information_schema.tables t
LEFT JOIN information_schema.columns c1
ON t.table_schema = c1.table_schema
AND t.table_name = c1.table_name
AND c1.column_key = 'PRI'
LEFT JOIN information_schema.columns c2
ON t.table_schema = c2.table_schema
AND t.table_name = c2.table_name
AND c2.extra = 'auto_increment'
WHERE t.table_schema = '............'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.