Bases de datos

MySQL

Consulta dinámica de cantidad de registros por tabla

Generación dinámica de SELECTs de conteo de registros de todas las tablas de la base de datos a la que se está conectado.

 
SELECT XSQL
FROM (
		SELECT  @ROWNUM := @ROWNUM + 1 AS ROWNUM,
			CONCAT(	CASE WHEN @ROWNUM  = 1 THEN '' ELSE ' union ' END,
					'select ''', table_name, ''' as TABLE_NAME, count(*) as NROWS from ', table_name) AS XSQL 
		FROM information_schema.tables a,   
				(SELECT @ROWNUM := 0) r
		WHERE a.table_schema = DATABASE() AND a.table_type = 'BASE TABLE'
        ORDER BY a.table_name 
        ) x
ORDER BY x.ROWNUM;