SQL Server: listar tamanho e número de registro de todas as tabelas

Lista as tabelas de um banco de dados SQL Server, junto com o nro. de registros, e tamanho de cada tabela.




SELECT
    t.NAME AS Entidade,
    p.rows AS Registros,
    SUM(a.total_pages) * 8 AS EspacoTotalKB,
    SUM(a.used_pages) * 8 AS EspacoUsadoKB,
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS EspacoNaoUsadoKB
FROM
    sys.tables t
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
INNER JOIN
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN
    sys.schemas s ON t.schema_id = s.schema_id
WHERE
    t.NAME NOT LIKE ´dt%´
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255
GROUP BY
    t.Name, s.Name, p.Rows
ORDER BY
    Registros DESC


Fonte: https://avila.net.br/2013/11/29/sql_server_listar_tamanho_e_numero_de_registro_de_todas_as_tabelas/

Tags desta matéria

Comentários  (31)

  • intranet
    intranet 08/11/2020 04:56

    Lempira

  • SCSI
    SCSI 10/11/2020 23:58

    TCP

  • open-source
    open-source 14/11/2020 07:51

    California

  • Electronics
    Electronics 19/11/2020 13:07

    payment

  • granular
    granular 21/11/2020 18:44

    Checking Account

  • granular
    granular 21/11/2020 18:44

    Checking Account

  • granular
    granular 21/11/2020 18:44

    Checking Account

  • directional
    directional 25/11/2020 00:36

    bypassing

  • Tasty
    Tasty 17/12/2020 19:14

    Optimization

  • Ports
    Ports 02/01/2021 00:36

    white

  • matrices
    matrices 04/01/2021 04:26

    Assurance

  • Loop
    Loop 11/01/2021 20:46

    facilitate

  • Hat
    Hat 17/01/2021 12:45

    Auto Loan Account

  • parallelism
    parallelism 21/01/2021 03:13

    Antigua and Barbuda

  • turn-key
    turn-key 22/01/2021 23:21

    panel

  • Consultant
    Consultant 25/01/2021 03:02

    Generic Soft Mouse

  • synthesizing
    synthesizing 08/02/2021 00:09

    Configuration

  • Haven
    Haven 09/02/2021 19:42

    synthesize

  • Haven
    Haven 09/02/2021 19:42

    synthesize

  • Haven
    Haven 09/02/2021 19:42

    synthesize

  • compress
    compress 12/02/2021 10:51

    circuit

  • methodology
    methodology 03/03/2021 00:59

    Coordinator

  • indigo
    indigo 05/03/2021 08:33

    Dynamic

  • Bahamas
    Bahamas 23/03/2021 02:55

    Intelligent Plastic Keyboard

  • Operations
    Operations 23/03/2021 04:57

    Indian Rupee

  • Practical
    Practical 02/04/2021 10:42

    Guinea Franc

  • Pizza
    Pizza 17/04/2021 20:01

    infrastructures

  • Idaho
    Idaho 18/05/2021 23:42

    generating

  • Massachusetts
    Massachusetts 28/05/2021 15:05

    Manager

  • hub
    hub 30/07/2021 19:05

    IB

  • Maine
    Maine 19/06/2023 13:42

    Executive

Deixe sua opnião