2017-09-15 55 views

回答

0

表數據庫

sp_MSForEachTable 'DECLARE @t AS VARCHAR(MAX); 
    SELECT @t = CAST(COUNT(1) as VARCHAR(MAX)) 
    + CHAR(9) + CHAR(9) + ''?'' FROM ? ; PRINT @t' 
0

是。你可以做所有這些事情從SQL就像這樣:

獲取數據庫名稱:

select DB_NAME() 

獲取表的數目:

select count(*) from sys.tables 

獲取索引的數量:

select count(*) from sys.indexes 

獲取使用的空間量:

exec sp_spaceused 

獲取數據庫所有者的用戶名:

select distinct suser_sname(owner_sid) from sys.databases 
0

我傾向於使用PowerShell這樣的事情。這裏是我的揮杆吧:

push-location; 
import-module sqlps -disablenamechecking; 
pop-location; 

$s = new-object microsoft.sqlserver.management.smo.server 'yourServer'; 

foreach ($db in $s.Databases | where {$_.IsAccessible -eq $true}) { 
    $r = @{TableCount = 0; 
     IndexCount = 0; 
     Name = $db.Name; 
     Size = $db.Size 
    } 
    $table_count = 0; 
    $index_count = 0; 
    foreach ($table in $db.Tables) { 
     $r.TableCount += 1; 
     $r.IndexCount += $table.Indexes.Count 
    } 
    $r | select-object @{name='name';expression={$_.name}}, 
     @{name='size';expression={$_.size}}, 
     @{name='TableCount';expression={$_.TableCount}}, 
     @{name='IndexCount';expression={$_.IndexCount}}; 
}