创建索引范例

目录

如下代码演示如何创建新的索引。索引针对表的两个列建立。

Sub CreateIndex()   Dim tbl As New Table
   Dim idx As New ADOX.Index
   Dim cat As New ADOX.Catalog' 打开目录。
   ' 打开目录。
   cat.ActiveConnection = _ 
      "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=c:\Program Files\Microsoft Office\" & _
      "Office\Samples\Northwind.mdb;"   ' 定义表并将其追加到目录
   tbl.Name = "MyTable"
   tbl.Columns.Append "Column1", adInteger
   tbl.Columns.Append "Column2", adInteger
   tbl.Columns.Append "Column3", adVarWChar, 50
   cat.Tables.Append tbl   ' 定义多列索引
   idx.Name = "multicolidx"
   idx.Columns.Append "Column1"
   idx.Columns.Append "Column2"   ' 将索引追加到表上
   tbl.Indexes.Append idxEnd Sub
www.51windows.Net