Home Forums SQL Server 2012 SQL 2012 - General SQL query to understand the names of all the available tables , number of records in these tables and size of these tables RE: SQL query to understand the names of all the available tables , number of records in these tables and size of these tables

  • Here's a quick query using system tables and reference:

    INFORMATION_SCHEMA: http://msdn.microsoft.com/en-us/library/ms186778.aspx

    Database Object Views: http://msdn.microsoft.com/en-us/library/ms189783.aspx

    SELECT

    table_name = t.name

    ,table_rowcnt = SUM(p.rows)

    FROM sys.tables t

    INNER JOIN sys.partitions p on p.object_id = t.object_id

    INNER JOIN sys.schemas s ON s.schema_id = t.schema_id

    WHERE t.is_ms_shipped = 0 and p.index_id in (1,0)

    GROUP by

    s.name, t.name