日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

SQL獲取數(shù)據(jù)庫(kù)中表信息:表名、建表時(shí)間、總行數(shù)、數(shù)據(jù)大小等

作者:小袁ITSuper 更新時(shí)間: 2022-05-06 編程語(yǔ)言

目錄

  • 寫(xiě)法1(推薦)
  • 寫(xiě)法2:只獲取庫(kù)中表名、行數(shù)建表時(shí)間
  • 寫(xiě)法3:只查看表名和建表時(shí)間
  • 寫(xiě)法4:有點(diǎn)小問(wèn)題,大佬幫忙改一下
  • 寫(xiě)法5:查看某個(gè)數(shù)據(jù)庫(kù)大小
  • 寫(xiě)法5:查看某個(gè)表

寫(xiě)法1(推薦)

SQL

USE [test] -- 只需修改這里的庫(kù)名

SELECT  a.name table_name, -- 表名
        a.crdate crdate, -- 建表時(shí)間
        b.rows rows, -- 總行數(shù)
        8*b.reserved/1024 reserved, -- 保留大小(MB)
        rtrim(8*b.dpages/1024) used, -- 已使用大小(MB)
        8*(b.reserved-b.dpages)/1024 unused -- 未使用大小(MB)
FROM    sysobjects AS a
        INNER JOIN sysindexes AS b ON a.id = b.id
WHERE   ( a.type = 'u' )
        AND ( b.indid IN ( 0, 1 ) )
ORDER BY a.name,b.rows DESC;

案例
在這里插入圖片描述

寫(xiě)法2:只獲取庫(kù)中表名、行數(shù)建表時(shí)間

SQL

USE [test] -- 只需修改這里的庫(kù)名

SELECT A.NAME ,B.ROWS,crdate 
FROM sysobjects A JOIN sysindexes B ON A.id = B.id 
WHERE A.xtype = 'U' AND B.indid IN(0,1) 
ORDER BY B.ROWS DESC

案例
在這里插入圖片描述

寫(xiě)法3:只查看表名和建表時(shí)間

SQL:

USE [test] -- 只需修改這里的庫(kù)名

select name,crdate from sysobjects where xtype = 'U'

案例
在這里插入圖片描述

寫(xiě)法4:有點(diǎn)小問(wèn)題,大佬幫忙改一下

SQL

select object_name(id) tablename,
		 8*reserved/1024 reserved,
		 rtrim(8*dpages/1024)+'Mb' used,
		 8*(reserved-dpages)/1024 unused,
       8*dpages/1024-rows/1024*minlen/1024 free,
       rows ,
       t.create_date,
       t.modify_date 
from sysindexes,sys.tables as t
where  object_name(id) = 'test1'

案例
在這里插入圖片描述

寫(xiě)法5:查看某個(gè)數(shù)據(jù)庫(kù)大小

SQL

exec sp_spaceused;

案例
在這里插入圖片描述

寫(xiě)法5:查看某個(gè)表

SQL

EXEC sp_spaceused 'test1'; -- 只需修改表名即可

案例
在這里插入圖片描述

原文鏈接:https://blog.csdn.net/yuan2019035055/article/details/122310131

欄目分類(lèi)
最近更新