Table.DataSpaceUsed Property
SQL Server 2008 R2
Gets the storage space used by the rows of the referenced table in kilobytes.
Assembly: Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)
The value is the actual amount of disk space that is required to store the row data of the referenced table. SQL Server can allocate additional, unused space to a Table object.
The following code example shows how to display the amount of storage space used by each table in the AdventureWorks2008R2 database.
C#
Server srv = new Server("(local)");
Database db = srv.Databases["AdventureWorks2008R2"];
foreach (Table tb in db.Tables)
{
Console.WriteLine("The " + tb.Name + " table is " + tb.DataSpaceUsed.ToString() + " KB in size.");
}
Powershell
$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $srv.Databases.Item("AdventureWorks2008R2")
Foreach ($tb in $db.Tables)
{
Write-Host "The" $tb.Name "table is" $tb.DataSpaceUsed "KB in size."
}
