{"id":139,"date":"2020-07-03T09:38:04","date_gmt":"2020-07-03T01:38:04","guid":{"rendered":"https:\/\/22pig.com\/?p=139"},"modified":"2020-07-03T09:38:04","modified_gmt":"2020-07-03T01:38:04","slug":"sql-server-%e6%9f%a5%e8%af%a2%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a1%a8%e5%8d%a0%e7%94%a8%e7%9a%84%e7%a9%ba%e9%97%b4%e5%8f%8a%e8%a1%8c%e6%95%b0","status":"publish","type":"post","link":"http:\/\/22pig.com\/?p=139","title":{"rendered":"SQL Server \u67e5\u8be2\u6570\u636e\u5e93\u8868\u5360\u7528\u7684\u7a7a\u95f4\u53ca\u884c\u6570"},"content":{"rendered":"<p><strong>&#8211;\u67e5\u8be2\u6240\u6709\u8868\u540d<\/strong><br \/>\nSELECT name, object_id, principal_id, schema_id, parent_object_id, type, type_desc, create_date, modify_date, is_ms_shipped, is_published,<br \/>\nis_schema_published, lob_data_space_id, filestream_data_space_id, max_column_id_used, lock_on_bulk_load, uses_ansi_nulls, is_replicated,<br \/>\nhas_replication_filter, is_merge_published, is_sync_tran_subscribed, has_unchecked_assembly_data, text_in_row_limit,<br \/>\nlarge_value_types_out_of_row<br \/>\nFROM sys.tables<\/p>\n<p><strong>&#8211;\u67e5\u8be2\u6570\u636e\u5e93\u4e2d\u6240\u6709\u7684\u8868\u540d\u53ca\u884c\u6570<\/strong><br \/>\nSELECT a.name, b.rows<br \/>\nFROM sys.sysobjects AS a INNER JOIN<br \/>\nsys.sysindexes AS b ON a.id = b.id<br \/>\nWHERE (b.indid IN (0, 1)) AND (a.type = &#8216;u&#8217;)<br \/>\nORDER BY a.name, b.rows DESC<\/p>\n<p><strong>&#8211;\u67e5\u8be2\u6240\u6709\u7684\u8868\u540d\u53ca\u7a7a\u95f4\u5360\u7528\u91cf\\\u884c\u6570<\/strong><br \/>\nSELECT OBJECT_NAME(id) AS tablename, 8 * reserved \/ 1024 AS reserved, RTRIM(8 * dpages) + &#8216;KB&#8217; AS used, 8 * (reserved &#8211; dpages) \/ 1024 AS unused,<br \/>\n8 * dpages \/ 1024 &#8211; rows \/ 1024 * minlen \/ 1024 AS free<br \/>\nFROM sys.sysindexes<br \/>\nWHERE (indid = 1)<br \/>\nORDER BY tablename, reserved DESC<\/p>\n<p><strong>&#8211;\u67e5\u8be2\u8868\u7a7a\u95f4\u5360\u7528(\u66f4\u51c6\u786e)<\/strong><\/p>\n<p>SELECT<br \/>\nt.NAME AS TableName,<br \/>\ns.Name AS SchemaName,<br \/>\np.rows AS RowCounts,<br \/>\nSUM(a.total_pages) * 8 AS TotalSpaceKB,<br \/>\nCAST(ROUND(((SUM(a.total_pages) * 8) \/ 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,<br \/>\nSUM(a.used_pages) * 8 AS UsedSpaceKB,<br \/>\nCAST(ROUND(((SUM(a.used_pages) * 8) \/ 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB,<br \/>\n(SUM(a.total_pages) &#8211; SUM(a.used_pages)) * 8 AS UnusedSpaceKB,<br \/>\nCAST(ROUND(((SUM(a.total_pages) &#8211; SUM(a.used_pages)) * 8) \/ 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB<br \/>\nFROM<br \/>\nsys.tables t<br \/>\nINNER JOIN<br \/>\nsys.indexes i ON t.OBJECT_ID = i.object_id<br \/>\nINNER JOIN<br \/>\nsys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id<br \/>\nINNER JOIN<br \/>\nsys.allocation_units a ON p.partition_id = a.container_id<br \/>\nLEFT OUTER JOIN<br \/>\nsys.schemas s ON t.schema_id = s.schema_id<br \/>\nWHERE<br \/>\nt.NAME NOT LIKE &#8216;dt%&#8217;<br \/>\nAND t.is_ms_shipped = 0<br \/>\nAND i.OBJECT_ID &gt; 255<br \/>\nGROUP BY<br \/>\nt.Name, s.Name, p.Rows<br \/>\nORDER BY<br \/>\np.rows desc<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8211;\u67e5\u8be2\u6240\u6709\u8868\u540d SELECT name, object_id, principal_id, schema_id, parent_object_id, type, type_desc, create_date, modify_date, is_ms_shipped, is_published, is_schema_published, lob_data_space_id, filestream_data_space_id, max_column_id_used, lock_on_bulk_load, uses_ansi_nulls, is_replicated, has_replication_filter, is_merge_published, is_sync_tran_subscribed, has_unchecked_assembly_data, text_in_row_limit, large_value_types_out_of_row FROM sys.tables &#8211;\u67e5\u8be2\u6570\u636e\u5e93\u4e2d\u6240\u6709\u7684\u8868\u540d\u53ca\u884c\u6570 SELECT a.name, b.rows FROM sys.sysobjects AS a INNER JOIN sys.sysindexes AS b ON a.id = b.id WHERE (b.indid IN (0, 1)) AND (a.type = &#8216;u&#8217;) ORDER [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"_links":{"self":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139"}],"version-history":[{"count":0,"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts\/139\/revisions"}],"wp:attachment":[{"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}