Table of Contents

Method CreateIndex

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

CreateIndex(Index, bool)

Creates a standard index on one or more columns of an existing table.

public void CreateIndex(Index index, bool overwrite = false)

Parameters

index Index

The Index object defining the index to create.

overwrite bool

If true, drops and recreates the index if it exists; if false, throws an error if it exists.

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var table = schema["users"];

    // Create an index on a single column
    var index = table.CreateIndex("idx_email", "email", IndexOrderType.Ascending);
    m.CreateIndex(index);

    // Create a composite index
    var compositeIndex = table.CreateIndex("idx_name_email");
    compositeIndex.AddIndexColumn("last_name", IndexOrderType.Ascending);
    compositeIndex.AddIndexColumn("first_name", IndexOrderType.Ascending);
    m.CreateIndex(compositeIndex);
}

Exceptions

DbException

Thrown when a database error occurs.