當前位置:首頁 » 編程語言 » 查詢SQL資料庫所有表格大小
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

查詢SQL資料庫所有表格大小

發布時間: 2022-04-07 01:36:03

❶ 如何查看sql server 資料庫大小

在MS Sql Server中可以能過以下的方法查詢出磁碟空間的使用情況及各資料庫數據文件及日誌文件的大小及使用利用率:
1、查詢各個磁碟分區的剩餘空間:
Exec master.dbo.xp_fixeddrives
2、查詢資料庫的數據文件及日誌文件的相關信息(包括文件組、當前文件大小、文件最大值、文件增長設置、文件邏輯名、文件路徑等)
select * from [資料庫名].[dbo].[sysfiles]
轉換文件大小單位為MB:
select name, convert(float,size) * (8192.0/1024.0)/1024. from [資料庫名].dbo.sysfiles
3、查詢當前資料庫的磁碟使用情況:
Exec sp_spaceused
4、查詢資料庫伺服器各資料庫日誌文件的大小及利用率
DBCC SQLPERF(LOGSPACE)

❷ 怎樣用SQL語句查詢一個資料庫中的所有表

查詢一個資料庫中的所有表sql語句是show tables;

顯示所有資料庫的命令是:show databases;要查看某個資料庫先要進入資料庫使用user <資料庫名>命令;進入資料庫之後才能查詢資料庫中有哪些表。使用以下命令即可查出所有表:

show tables;

(2)查詢SQL資料庫所有表格大小擴展閱讀

mysql資料庫的基本sql操作命令介紹:

1、顯示當前資料庫伺服器中的資料庫列表:mysql> SHOW DATABASES;

2、建立資料庫:mysql> CREATE DATABASE 庫名;

3、建立數據表:mysql> USE 庫名;mysql> CREATE TABLE 表名 (欄位名 VARCHAR(20), 字

名 CHAR(1));

4、刪除資料庫:mysql> DROP DATABASE 庫名;

5、刪除數據表:mysql> DROP TABLE 表名;

6、將表中記錄清空:mysql> DELETE FROM 表名;

7、往表中插入記錄:mysql> INSERT INTO 表名 VALUES ("hyq","M");

8、更新表中數據:mysql-> UPDATE 表名 SET 欄位名1='a',欄位名2='b' WHERE 欄位名3='c';

9、用文本方式將數據裝入數據表中:mysql> load data local infile "d:/mysql.txt" into table 表名;

10、導入.sql文件命令:mysql> USE 資料庫名;mysql> source d:/mysql.sql;

❸ 如何使用SQL語句查詢資料庫及表的空間容量

--1、查看錶空間的名稱及大小
select
t.tablespace_name,
round(sum(bytes/(1024*1024)),0)
ts_size
from
dba_tablespaces
t,
dba_data_files
d
where
t.tablespace_name
=
d.tablespace_name
group
by
t.tablespace_name;
--2、查看錶空間物理文件的名稱及大小
select
tablespace_name,
file_id,
file_name,
round(bytes/(1024*1024),0)
total_space
from
dba_data_files
order
by
tablespace_name;
3.查看所有表空間使用情況
select
b.file_id
文件ID號,
b.tablespace_name
表空間名,
b.bytes/1024/1024||'M'位元組數,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024||'M'
已使用,
sum(nvl(a.bytes,0))/1024/1024||'M'
剩餘空間,
round(100
-
sum(nvl(a.bytes,0))/(b.bytes)*100,2)||
'%'
佔用百分比
from
dba_free_space
a,dba_data_files
b
where
a.file_id=b.file_id
group
by
b.tablespace_name,b.file_id,b.bytes
order
by
b.file_id;
總有一款適合你!

❹ 有沒有語句能查詢SQL資料庫中每一個表的大小

--得到資料庫中所有表的空間/記錄情況
exec sp_MSForEachTable
@precommand=N'
create table ##(
id int identity,
表名 sysname,
欄位數 int,
記錄數 int,
保留空間 Nvarchar(10),
使用空間 varchar(10),
索引使用空間 varchar(10),
未用空間 varchar(10))',
@command1=N'insert ##(表名,記錄數,保留空間,使用空間,索引使用空間,未用空間) exec sp_spaceused ''?''

update ## set 欄位數=(select count(*) from syscolumns where id=object_id(''?''))
where id=scope_identity()', @postcommand=N'select * from ## order by id drop table ##'

❺ MySQL中查詢所有資料庫佔用磁碟空間大小和單個庫中所有表的大小的sql語句

查詢所有資料庫佔用磁碟空間大小的SQL語句:
復制代碼
代碼如下:
select
TABLE_SCHEMA,
concat(truncate(sum(data_length)/1024/1024,2),'
MB')
as
data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB')
as
index_size
from
information_schema.tables
group
by
TABLE_SCHEMA
order
by
data_length
desc;
查詢單個庫中所有表磁碟佔用大小的SQL語句:
復制代碼
代碼如下:
select
TABLE_NAME,
concat(truncate(data_length/1024/1024,2),'
MB')
as
data_size,
concat(truncate(index_length/1024/1024,2),'
MB')
as
index_size
from
information_schema.tables
where
TABLE_SCHEMA
=
'TestDB'
group
by
TABLE_NAME
order
by
data_length
desc;
以上語句測試有效,注意替換以上的TestDB為資料庫名

❻ 如何查看SQL2000資料庫中所有表的數據量大小

直接在查詢分析器運行即可:
declare @id int
declare @type character(2)
declare @pages
int
declare @dbname sysname
declare @dbsize dec(15,0)
declare @bytesperpage dec(15,0)
declare @pagesperMB dec(15,0)

create table #spt_space
(
objid int null,
rows int null,
reserved dec(15) null,
data dec(15) null,
indexp dec(15) null,
unused dec(15) null
)

set nocount on

-- Create a cursor to loop through the user tables
declare c_tables cursor for
select id
from sysobjects
where xtype = 'U'

open c_tables

fetch next from c_tables
into @id

while @@fetch_status = 0
begin

/* Code from sp_spaceused */
insert into #spt_space (objid, reserved)
select objid = @id, sum(reserved)
from sysindexes
where indid in (0, 1, 255)
and id = @id

select @pages = sum(dpages)
from sysindexes
where indid < 2
and id = @id
select @pages = @pages + isnull(sum(used), 0)
from sysindexes
where indid = 255
and id = @id
update #spt_space
set data = @pages
where objid = @id

/* index: sum(used) where indid in (0, 1, 255) - data */
update #spt_space
set indexp = (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
- data
where objid = @id

/* unused: sum(reserved) - sum(used) where indid in (0, 1, 255) */
update #spt_space
set unused = reserved
- (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
where objid = @id

update #spt_space
set rows = i.rows
from sysindexes i
where i.indid < 2
and i.id = @id
and objid = @id

fetch next from c_tables
into @id
end

select TableName = (select left(name,60) from sysobjects where id = objid),
Rows = convert(char(11), rows),
ReservedKB = ltrim(str(reserved * d.low / 1024.,15,0) + ' ' + 'KB'),
DataKB = ltrim(str(data * d.low / 1024.,15,0) + ' ' + 'KB'),
IndexSizeKB = ltrim(str(indexp * d.low / 1024.,15,0) + ' ' + 'KB'),
UnusedKB = ltrim(str(unused * d.low / 1024.,15,0) + ' ' + 'KB')

from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = 'E'
order by reserved desc
drop table #spt_space
close c_tables
deallocate c_tables

❼ 怎樣用SQL語句查詢一個資料庫中的所有表

1、打開Microsoft SQL Server 2012,選中需要查詢所有表的資料庫。

❽ 如何查看SQLServer資料庫每個表佔用的空間大小

創建存儲過程:

CREATE PROCEDURE [dbo].[sys_viewTableSpace]
AS

BEGIN

SET NOCOUNT ON;

CREATE TABLE [dbo].#tableinfo(
表名 [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
記錄數 [int] NULL,
預留空間 [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
使用空間 [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
索引佔用空間 [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
未用空間 [varchar](50) COLLATE Chinese_PRC_CI_AS NULL
)

insert into #tableinfo(表名, 記錄數, 預留空間, 使用空間, 索引佔用空間, 未用空間)
exec sp_MSforeachtable "exec sp_spaceused '?'"

select * from #tableinfo
order by 記錄數 desc

drop table #tableinfo

END

使用的時候直接 :exec sys_viewtablespace

❾ 如何查詢sqlserver資料庫中數據的大小

不是很懂你的問題意思,下次提問請描述的更清楚一些;

如果是想知道某一個表佔用了多大空間,你可以用下面的語句

useyourDB
go
sp_spaceusedyourTable

你會得到如下結果,各列分別是:

表名;行數;已佔用空間;數據佔用空間;索引佔用空間;未使用空間;