Table of Contents

Method CreateTable

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

CreateTable(Table, bool)

Creates a table in the database with all its columns, constraints, and indexes, optionally overwriting if it exists.

public void CreateTable(Table table, bool overwrite = false)

Parameters

table Table

The Table object defining the table to be created.

overwrite bool

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

Examples

using (var m = new Manager(conn))
{
    var schema = Schema.NewSchema("app");
    var table = schema.CreateTable("orders");
    table.CreateColumn("id", DataType.Integer, autoGenerate: true);
    table.CreateColumn("total", DataType.Decimal, precision: 10, scale: 2);
    table.CreatePrimaryKey("pk_orders", "id");

    // Overwrite table if it exists
    m.CreateTable(table, overwrite: true);
}

Exceptions

DbException

Thrown when a database error occurs.