Method CreateConstraint
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
CreateConstraint(Constraint)
Creates a constraint (primary key, foreign key, unique, check, or default) on an existing table.
public void CreateConstraint(Constraint constraint)
Parameters
constraintConstraintThe Constraint object to create (e.g., PrimaryKey, ForeignKey, Unique).
Examples
using (var m = new Manager(conn))
{
var schema = m.LoadSchema("app");
var ordersTable = schema["orders"];
var fk = ordersTable.CreateForeignKey(
"fk_orders_customers",
"customer_id",
schema.Name,
"customers",
"id",
ForeignKeyRuleType.Cascade,
ForeignKeyRuleType.Restrict
);
m.CreateConstraint(fk);
}
Exceptions
- DbException
Thrown when a database error occurs.