Method CreateTable
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
CreateTable(Table)
Creates a table in the database with all its columns, constraints, and indexes.
public void CreateTable(Table table)
Parameters
Examples
using (var m = new Manager(conn))
{
var schema = new Schema("app");
var table = new Table(schema, "customers");
table.AddColumn(new Column("id", DataType.Integer) { PrimaryKey = true, AutoIncrement = true });
table.AddColumn(new Column("name", DataType.VarChar, 100) { NotNull = true });
table.AddColumn(new Column("email", DataType.VarChar, 255));
m.CreateTable(table);
}
Exceptions
- DbException
Thrown when a database error occurs or if the table already exists.
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)
Parameters
tableTableThe Table object defining the table to be created.
overwriteboolIf 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 = new Schema("app");
var table = new Table(schema, "orders");
table.AddColumn(new Column("id", DataType.Integer) { PrimaryKey = true });
table.AddColumn(new Column("total", DataType.Decimal) { Precision = 10, Scale = 2 });
// Overwrite table if it exists
m.CreateTable(table, overwrite: true);
}
Exceptions
- DbException
Thrown when a database error occurs.