您可以使用INFORMATION_SCHEMA.TABLES和AVG_ROW_LENGTH在MySQL中查询平均行长-
SELECT AVG_ROW_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ‘yourTableName’;
让我们首先创建一个表-
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100) );
使用插入命令在表中插入记录-
mysql> insert into DemoTable(StudentName) values('John'); mysql> insert into DemoTable(StudentName) values('Larry'); mysql> insert into DemoTable(StudentName) values('Sam'); mysql> insert into DemoTable(StudentName) values('Mike');
使用选择命令显示表中的记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | John | | 2 | Larry | | 3 | Sam | | 4 | Mike | +-----------+-------------+ 4 rows in set (0.00 sec)
在MySQL中查询平均行长-
mysql> SELECT AVG_ROW_LENGTH FROM information_schema.tables WHERE TABLE_NAME = 'DemoTable';
这将产生以下输出-
+----------------+ | AVG_ROW_LENGTH | +----------------+ | 4096 | +----------------+ 1 row in set (0.11 sec)