{"id":1465,"date":"2019-11-07T10:15:19","date_gmt":"2019-11-07T13:15:19","guid":{"rendered":"https:\/\/www.franklinjr.com\/blog\/?p=1465"},"modified":"2019-11-07T10:18:33","modified_gmt":"2019-11-07T13:18:33","slug":"verificando-espaco-das-tabelas-de-uma-base-sql-server","status":"publish","type":"post","link":"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/07\/verificando-espaco-das-tabelas-de-uma-base-sql-server\/","title":{"rendered":"Verificando espa\u00e7o das tabelas de uma base SQL Server"},"content":{"rendered":"\n<p>Para verificar o espa\u00e7o utilizado em todas as tabelas de um banco SQL Server, rode a seguinte query no banco<\/p>\n\n\n\n<pre lang=\"SQL\">SELECT \n    t.NAME AS TableName,\n    s.Name AS SchemaName,\n    p.rows AS RowCounts,\n    SUM(a.total_pages) * 8 AS TotalSpaceKB, \n    CAST(ROUND(((SUM(a.total_pages) * 8) \/ 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,\n    SUM(a.used_pages) * 8 AS UsedSpaceKB, \n    CAST(ROUND(((SUM(a.used_pages) * 8) \/ 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, \n    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,\n    CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) \/ 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB\nFROM \n    sys.tables t\nINNER JOIN      \n    sys.indexes i ON t.OBJECT_ID = i.object_id\nINNER JOIN \n    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id\nINNER JOIN \n    sys.allocation_units a ON p.partition_id = a.container_id\nLEFT OUTER JOIN \n    sys.schemas s ON t.schema_id = s.schema_id\nWHERE \n    t.NAME NOT LIKE 'dt%' \n    AND t.is_ms_shipped = 0\n    AND i.OBJECT_ID &gt; 255 \nGROUP BY \n    t.Name, s.Name, p.Rows\nORDER BY \n    UsedSpaceMB DESC\n<\/pre>\n\n\n\n<p>Salve StackOverflow:  <a href=\"https:\/\/stackoverflow.com\/questions\/7892334\/get-size-of-all-tables-in-database\">https:\/\/stackoverflow.com\/questions\/7892334\/get-size-of-all-tables-in-database<\/a> <\/p>\n\n\n\n<p>Veja tamb\u00e9m:  <a href=\"https:\/\/www.franklinjr.com\/blog\/index.php\/2016\/08\/15\/pegar-tamanho-das-bases-no-sql-server\/\">Pegar tamanho das bases no SQL Server<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Para verificar o espa\u00e7o utilizado em todas as tabelas de um banco SQL Server, rode a seguinte query no banco SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, CAST(ROUND(((SUM(a.total_pages) * 8) \/ 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB, SUM(a.used_pages) * 8 AS UsedSpaceKB, CAST(ROUND(((SUM(a.used_pages) * 8) \/ [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[506,441],"tags":[],"class_list":["post-1465","post","type-post","status-publish","format-standard","hentry","category-sql-2","category-sql-server-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\r\n<title>Verificando espa\u00e7o das tabelas de uma base SQL Server - Franklin Jr.<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/07\/verificando-espaco-das-tabelas-de-uma-base-sql-server\/\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/07\/verificando-espaco-das-tabelas-de-uma-base-sql-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\/\/www.franklinjr.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Verificando espa\u00e7o das tabelas de uma base SQL Server\"}]}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Verificando espa\u00e7o das tabelas de uma base SQL Server - Franklin Jr.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/07\/verificando-espaco-das-tabelas-de-uma-base-sql-server\/","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BreadcrumbList","@id":"https:\/\/www.franklinjr.com\/blog\/index.php\/2019\/11\/07\/verificando-espaco-das-tabelas-de-uma-base-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/www.franklinjr.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Verificando espa\u00e7o das tabelas de uma base SQL Server"}]}]}},"_links":{"self":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1465"}],"version-history":[{"count":4,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1465\/revisions"}],"predecessor-version":[{"id":1472,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1465\/revisions\/1472"}],"wp:attachment":[{"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.franklinjr.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}