Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  
fulvio

Script que retorna o espaço ocupado pelas Tabelas

Question

Pessoal,

Segue script que retorna o espaço ocupado pelas Tabelas, seus índices, quantidade de linhas de cada tabela e o tamanho de reserva (tamanhos em KB)

CREATE TABLE #Tabela (NomeTabela VARCHAR(256), Controle TINYINT)
CREATE TABLE #Tamanho (NomeTabela VARCHAR(256), QuantidadeLinhas int, TamanhoReverva VARCHAR(15), TamanhoTabela VARCHAR(15), TamanhoIndice VARCHAR(15), SemUso VARCHAR(15))
INSERT INTO #Tabela (NomeTabela)
SELECT name FROM sysobjects WHERE xtype='U'

DECLARE @Tabela VARCHAR(256)

WHILE (SELECT TOP 1 1 FROM #Tabela WHERE Controle IS NULL) = 1
BEGIN
    SET @Tabela = (SELECT TOP 1 NomeTabela FROM #Tabela WHERE Controle IS NULL)
    INSERT INTO #Tamanho (NomeTabela, QuantidadeLinhas, TamanhoReverva, TamanhoTabela, TamanhoIndice, SemUso) 
    EXEC sp_spaceused @Tabela
    UPDATE #Tabela SET Controle = 1 WHERE NomeTabela = @Tabela
END
SELECT * FROM #Tamanho ORDER BY 1

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  



  • Forum Statistics

    • Total Topics
      148393
    • Total Posts
      643786
×
×
  • Create New...