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 email column
    var index = new Index("idx_email", table);
    index.AddColumn(table["email"]);
    m.CreateIndex(index);

    // Create a composite index
    var compositeIndex = new Index("idx_name_email", table);
    compositeIndex.AddColumn(table["last_name"]);
    compositeIndex.AddColumn(table["first_name"]);
    m.CreateIndex(compositeIndex);
}

Exceptions

DbException

Thrown when a database error occurs.