Tuesday, 8 October 2019

MSSQL server script to provide tables names and its row count in a DB

SELECT 
    TableName = t.NAME,
    TableSchema = s.Name,
    RowCounts = p.rows
FROM 
    sys.tables t
INNER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
WHERE 
    t.is_ms_shipped = 0
GROUP BY
    t.NAME, s.Name, p.Rows
ORDER BY 
    s.Name, t.Name
ref link: https://stackoverflow.com/questions/9954775/script-that-provides-the-row-counts-and-table-names

No comments:

Post a Comment

The total number of locks exceeds the lock table size

 SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; SET GLOBAL innodb_buffer_pool_size = 2147483648;  -- 2GB Note: The value is in byte...