Table.HasClusteredIndex Property

 

Applies To: SQL Server 2016 Preview

Gets the Boolean property value that specifies whether the table has a clustered index.

Namespace:   Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

Syntax

[SfcPropertyAttribute(SfcPropertyFlags.None | SfcPropertyFlags.Standalone | SfcPropertyFlags.SqlAzureDatabase | SfcPropertyFlags.Matrix)]
public bool HasClusteredIndex { get; }
public:
[SfcPropertyAttribute(SfcPropertyFlags::None | SfcPropertyFlags::Standalone | SfcPropertyFlags::SqlAzureDatabase | SfcPropertyFlags::Matrix)]
property bool HasClusteredIndex {
    bool get();
}
[<SfcPropertyAttribute(SfcPropertyFlags.None | SfcPropertyFlags.Standalone | SfcPropertyFlags.SqlAzureDatabase | SfcPropertyFlags.Matrix)>]
member HasClusteredIndex : bool with get
<SfcPropertyAttribute(SfcPropertyFlags.None Or SfcPropertyFlags.Standalone Or SfcPropertyFlags.SqlAzureDatabase Or SfcPropertyFlags.Matrix)>
Public ReadOnly Property HasClusteredIndex As Boolean

Property Value

Type: System.Boolean

A Boolean value that specifies whether there is a clustered index defined on the table.

If True, there is a clustered index defined on the table. Otherwise, False (default).

Remarks

The B-tree leaf level of a clustered index is the rows of data.

Examples

Legacy Code Example

The following code example shows how to check each table in the AdventureWorks2012 database to see if it has a clustered index.

C#

Server srv = new Server("(local)");
Database db = srv.Databases["AdventureWorks2012"];

Foreach (Table tb in db.Tables) 
{
   Console.WriteLine("The " + tb.Name + " table has a clustered index:" + tb.HasClusteredIndex.ToString());
}

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $srv.Databases.Item("AdventureWorks2012")

Foreach ($tb in $db.Tables) 
{
   Write-Host "The" $tb.Name "table has a clustered index:" $tb.HasClusteredIndex
}

See Also

Table Class
Microsoft.SqlServer.Management.Smo Namespace

CREATE TABLE (Transact-SQL)
Unable to find linked topic '811e00f9-303f-42b5-8bd4-2cdb829c84e9'.

Return to top