sybase数据库常用SQL积累
场景1:user connection配置了1500,数据库日志里面发现报错连接用完,需要定位是哪个机器或用户产生了大量连接
SQL语句:
select * from (select b.name,a.hostname,a.program_name,count(*) counts from master..sysprocesses a,数据库1..sysusers b where a.suid=b.suid group by name,hostname,program_name union select b.name,a.hostname,a.program_name,count(*) counts from master..sysprocesses a,数据库2..sysusers b where a.suid=b.suid group by name,hostname,program_name ) tmp order by counts desc
场景2:查看数据库中运行时间较长的语句
SQL:select datediff(mi,starttime, getdate()) as time , * from master..syslogshold
场景3:查看某个参数的配置
方法一:sp_confiugre "参数名"
方法二:使用下面SQL语句进行查询:
select b.name, c.value,c.memory_used, c.minimum_value, c.maximum_value, c.defvalue,c.unit
from master.dbo.sysconfigures b, master.dbo.syscurconfigs c
where b.config*=c.config and parent!=19 and b.config > 100 and name like '%参数名片段%'
order by name
场景4:查看参数配置及历史使用情况
--全部配置: sp_monitorconfig 'all'
--单个参数: sp_monitorconfig "参数名"
场景5:查看存储过程使用内存情况
dbcc traceon(3604)
dbcc memusage
dbcc traceoff(3604)