MYSQL 查询表信息,总数据量

0. 究极无敌SQL语句,查询表名,表注释,创建时间,最后更新时间,数据量

SELECT 
	`TABLE_NAME` as `表名`, `TABLE_COMMENT` as `表注释`, `table_rows`, 
	`CONCAT(TRUNCATE(table_rows/10000,2),' 万')` AS `table_rows_wan`, 
	`CONCAT(TRUNCATE(table_rows/100000000,2),' 亿')` AS `table_rows_yi`, 
	`CONCAT(TRUNCATE(data_length/1024/1024/1024,2),' GB')` AS `data_size_GB`,
	`CONCAT(TRUNCATE(data_length/1024/1024,2),' MB')` AS `data_size_MB`, 
	`UPDATE_TIME` as `最后更新时间`, 
	`CREATE_TIME`
FROM 
	`information_schema`.`tables` 
WHERE 
	`TABLE_SCHEMA` = 'your_db_name' 
ORDER BY 
	`UPDATE_TIME` `desc`, 
	`TABLE_NAME`, 
	`TABLE_ROWS` `desc`;

1. MYSQL 查询数据表最后更新时间

SELECT 
	`TABLE_NAME`, `CREATE_TIME`, `UPDATE_TIME` 
FROM 
	`information_schema`.`TABLES` 
WHERE 
	`information_schema`.`TABLES`.`TABLE_SCHEMA` = 'your_db_name'

2. MYSQL 查询数据库所有表名和表注释

SELECT 
	`TABLE_NAME`,`TABLE_COMMENT`
FROM 
	`information_schema`.`TABLES`
WHERE 
	`table_schema` = 'your_db_name'; 

3. MYSQL 查询指定库数据表数量

SELECT 
	`COUNT(*)` as `TABLES`, `table_schema`
FROM 
	`information_schema`.`TABLES`   
WHERE 
	`table_schema` = 'your_db_name';

4. 查询数据库字段

 #查询一个表中有多少字段
 SELECT 
 	`COUNT(*)` 
 FROM 
 	`information_schema`.`COLUMNS` 
 WHERE 
 	`table_schema` = 'your_db_name' AND 
 	`table_name` = 'your_table_name';
 
 #查询一个数据库中有多少字段
 SELECT 
 	`COUNT(column_name)` 
 FROM 
 	`information_schema`.`COLUMNS` 
 WHERE 
 	`TABLE_SCHEMA` = 'your_db_name';
 
 #查询数据库中所以表、字段、字段类型、注释等信息
 SELECT 
 	`TABLE_NAME`, `column_name`, `DATA_TYPE`, `column_comment` 
 FROM 
 	`information_schema`.`COLUMNS` 
 WHERE 
 	`TABLE_SCHEMA` = 'your_db_name' ;

猜你喜欢

转载自blog.csdn.net/zhw21w/article/details/126954887