Indexes
You can retrieve information on indexes, such as the primary keys, by querying the Indexes collection.
Retrieving Primary Key Information
To retrieve this schema collection, call the GetSchema method of the EmailConnection class. You can restrict the results by table name. The following example retrieves the primary key of the IMAP table [INBOX].
C#
String connectionString = "Port=993;Server=outlook.office365.com;Password=password;User=user;Protocol=IMAP;SMTP Port=587;SMTP Server=smtp.office365.com;"; using (EmailConnection conn = new EmailConnection(connectionString)) { conn.Open(); DataTable databaseSchema = conn.GetSchema("Indexes", new string[] {"[INBOX]"}); foreach (DataRow row in databaseSchema.Rows) { Console.WriteLine(row["INDEX_NAME"]); Console.WriteLine(row["PRIMARY"]); } }
VB.NET
Dim connectionString As String = "Port=993;Server=outlook.office365.com;Password=password;User=user;Protocol=IMAP;SMTP Port=587;SMTP Server=smtp.office365.com;" Using conn As New EmailConnection(connectionString) conn.Open() Dim databaseSchema As DataTable = conn.GetSchema("Indexes", New String() {"[INBOX]"}) For Each row As DataRow In databaseSchema.Rows Console.WriteLine(row("INDEX_NAME")) Console.WriteLine(row("PRIMARY")) Next End Using
Columns Returned
The Indexes schema collection contains the following columns:
Column Name | Data Type | Description |
INDEX_CATALOG | System.String | The name of the database containing the index. |
INDEX_SCHEMA | System.String | The name of the schema containing the index. |
TABLE_NAME | System.String | The name of the table containing the index. |
INDEX_NAME | System.String | The name of the index. |
UNIQUE | System.Boolean | Whether the index is unique. |
PRIMARY | System.Boolean | Whether the index is a primary key. |
TYPE | System.Int32 | An integer value corresponding to the index type: statistic (0), clustered (1), hashed (2), or other (3). |
COMMENT | System.String | A description of the index. |