Identify Total Row Count for Databases
Learn how to identify your total row count for different databases in order to help estimate your MAR. You can roughly estimate your MAR by taking 10-20% of the total rows in your database, though your actual MAR will vary depending on the specifics of your database use case.
Sample scripts
Use the sample scripts for your database type to find your database's total row count.
Oracle
Run the following command to find row counts for all tables in a schema:
TIP: This approach relies on the latest LAST_ANALYZED value. For the most accurate result, run the following command before the row count command:
exec dbms_stats.gather_schema_stats('SCHEMANAME')
select table_name, num_rows
from user_tables;
SQL Server
Run the following command to find row counts for all tables in a SQL Server database:
SELECT
QUOTENAME(SCHEMA_NAME(sOBJ.schema_id)) + '.' + QUOTENAME(sOBJ.name) AS [TableName]
, SUM(sPTN.Rows) AS [RowCount]
FROM
sys.objects AS sOBJ
INNER JOIN sys.partitions AS sPTN
ON sOBJ.object_id = sPTN.object_id
WHERE
sOBJ.type = 'U'
AND sOBJ.is_ms_shipped = 0x0
AND index_id < 2 -- 0:Heap, 1:Clustered
GROUP BY
sOBJ.schema_id
, sOBJ.name
ORDER BY [TableName]
GO
PostgreSQL
Run the following command to find row counts for all tables in a single schema:
SELECT schemaname,relname,n_live_tup
FROM pg_stat_user_tables
WHERE schemaname = 'PUBLIC'
ORDER BY n_live_tup DESC;
Or run the following command to find row counts for all tables in all schemas:
SELECT schemaname,relname,n_live_tup
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC;
MySQL
Run the following command to find row counts for all tables in a MySQL database:
SELECT
TABLE_NAME,
TABLE_ROWS
FROM
`information_schema`.`tables`
WHERE
`table_schema` = 'YOUR_DB_NAME';