SqlServer统计用户登录次数
1、查询近一年每月登录次数
--查询近一年每月访问次数
select YM as 年月,count(1) as 登录次数 from
(select Account,CONVERT(VarChar(7), OpDate, 120) as YM from OPLOG
where OpDate > dateadd(year,-1,GETDATE()) and OpCata = '用户登录') as a
group by YM order by YM asc;
2、查询数据库大小,空间占用
SELECT 8*SUM(b.dpages)/1024 占用空间MB FROM sysobjects AS a
INNER JOIN sysindexes AS b ON a.id = b.id WHERE a.xtype='U' AND b.indid=1;
3、查询数据库总记录数
SELECT SUM(b.rows) AS 总记录数 FROM sysobjects AS a
INNER JOIN sysindexes AS b ON a.id = b.id WHERE a.xtype='U' AND b.indid=1;