예제 #1
0
 public ActionResult Stat()
 {
     try {
         const string sql      = @"SELECT '[' + SCHEMA_NAME(t.schema_id) + '].[' + t.name + ']' AS fullTableName, SCHEMA_NAME(t.schema_id) AS schemaName, t.name AS TableName, i.rows AS Rows, t.create_date AS Created, t.modify_date AS Modified
                     FROM sys.tables AS t INNER JOIN sys.sysindexes AS i ON t.object_id = i.id AND i.indid < 2
                     WHERE SCHEMA_NAME(t.schema_id) != 'dbo'
                     ORDER BY schemaName, fullTableName";
         var          counters = AdminDb.ExecuteQuery <StatCounter>(sql).ToList();
         const string size     = @"SELECT DatabaseName = DB_NAME(database_id), 
                     LogSize = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2)),
                     RowSize = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2)),
                     TotalSize = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
                     FROM sys.master_files WITH(NOWAIT)
                     WHERE database_id = DB_ID() -- for current db 
                     GROUP BY database_id";
         var          model    = AdminDb.ExecuteQuery <DbCounter>(size).ToList().Single();
         model.StatCounters = counters;
         return(View(model));
     } catch (Exception ex) {
         return(View(new DbCounter()
         {
             Databasename = "Function not available"
         }));
     }
 }