Method BuildTable
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
BuildTable(Table, bool, bool)
Creates or recreates a table in the database including all columns, constraints, and indexes.
public void BuildTable(Table table, bool overwrite = false, bool ignoreWarnings = false)
Parameters
tableTableA Table object defining the table structure to create.
overwriteboolIf true, drops and recreates the table if it already exists; if false, throws an error if the table exists.
ignoreWarningsboolIf true, ignores warnings for operations not supported by the database (e.g., certain constraint types).
Examples
var conn = new MySqlDatasourceConnection
{
Hostname = "localhost",
Port = 3306,
Username = "root",
Password = "password",
Database = "mydb"
};
using (var m = new Manager(conn))
{
var schema = new Schema("app");
var table = new Table(schema, "users");
table.AddColumn(new Column("id", DataType.Integer) { PrimaryKey = true, AutoIncrement = true });
table.AddColumn(new Column("email", DataType.VarChar, 255));
// Build the table (will fail if it exists)
m.BuildTable(table);
// Or overwrite if it exists
m.BuildTable(table, overwrite: true);
}
Exceptions
- DbException
Thrown when a database error occurs.