Clustered Property Example (VB)

Microsoft ActiveX Data Objects (ADO)

Clustered Property Example (VB)

This example demonstrates the Clustered property of an Index. Note that Microsoft Jet databases do not support clustered indexes, so this example will return False for the Clustered property of all indexes in the Northwind database.

Sub ClusteredX()
    Dim cnn As New ADODB.Connection
    Dim cat As New ADOX.Catalog
    Dim tblLoop As ADOX.Table
    Dim idxLoop As ADOX.Index
    Dim strCnn as String

   StrCnn = "Provider=SQLOLEDB;Data Source=srv;Initial Catalog=pubs;" & _
            "User Id=sa;Password=;"
    ' Connect the catalog.
   cnn.Open strCnn
    cat.ActiveConnection = cnn
    
    ' Enumerate Tables
    For Each tblLoop In cat.Tables
        'Enumerate Indexes
        For Each idxLoop In tblLoop.Indexes
            Debug.Print tblLoop.Name & " " & _
                idxLoop.Name & " " & idxLoop.Clustered
        Next idxLoop
    Next tblLoop

End Sub