Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Samual Sam

You can use INFORMATION_SCHEMA.TABLES and AVG_ROW_LENGTH to query average row length in MySQL −

SELECT AVG_ROW_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ‘yourTableName’;

Let us first create a table −

mysql> create table DemoTable
(
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   StudentName varchar(100)
);
Query OK, 0 rows affected (0.90 sec)

Insert records in the table using insert command −

mysql> insert into DemoTable(StudentName) values('John');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable(StudentName) values('Larry');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable(StudentName) values('Sam');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable(StudentName) values('Mike');
Query OK, 1 row affected (0.15 sec)

Display records from the table using select command −

mysql> select *from DemoTable;

This will produce the following output −

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
| 1         | John        |
| 2         | Larry       |
| 3         | Sam         |
| 4         | Mike        |
+-----------+-------------+
4 rows in set (0.00 sec)

Query average row length in MySQL −

mysql> SELECT AVG_ROW_LENGTH FROM information_schema.tables WHERE TABLE_NAME = 'DemoTable';

This will produce the following output −

+----------------+
| AVG_ROW_LENGTH |
+----------------+
| 4096           |
+----------------+
1 row in set (0.11 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.