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 = Schema.NewSchema("app");
var table = schema.CreateTable("users");
table.CreateColumn("id", DataType.Integer, autoGenerate: true);
table.CreateColumn("email", DataType.VarChar, size: 255);
table.CreatePrimaryKey("pk_users", "id");
// Build the table — throws if it already exists
m.BuildTable(table);
// Pass overwrite: true to drop and recreate if it already exists
// m.BuildTable(table, overwrite: true);
}
Exceptions
- DbException
Thrown when a database error occurs.