— 查询中的所有数据库名:
— show databases; — mysql
select name from master..sysdatabases order by name;
— 查询数据库中表名
— use zabbix; show tables; — mysql
use [db_name]
select name from sysobjects where xtype=’u’ order by name;
— 查询数据库连接
select connection_id,c.session_id,connect_time,client_net_address,client_tcp_port,host_name,program_name,login_name,row_count
from sys.dm_exec_connections c join sys.dm_exec_sessions s on s.session_id = c.session_id
where s.session_id in(select spid from [master].[dbo].[sysprocesses] where [dbid] in
(select [dbid] from [master].[dbo].[sysdatabases] where name=’db_name’));
— 查询数据库服务器各数据库日志文件的大小及利用率
dbcc sqlperf(logspace)
— 查询数据库的数据文件及日志文件的相关信息
select * from [db_name].[dbo].[sysfiles];
select name, convert(float,size)*(8192.0/1024.0)/1024.0 from [db_name].dbo.sysfiles;
— 查询数据库 数据文件使用情况
use [db_name]
go
select name, data_space_id 文件组id, size/128 [文件大小(兆)],
fileproperty(name, ‘spaceused’)/128 [已用空间(兆)],
size/128 – fileproperty(name, ‘spaceused’)/128 [未用空间(兆)],
fileproperty(name, ‘spaceused’)*100.0/size [使用率(%)],
max_size/128 [最大值(兆)], growth 增长值, is_percent_growth 是否百分比增长, physical_name 物理路径
from sys.database_files a;