Class Default
- Namespace
- YndigoBlue.Velocity.Constraints
- Assembly
- YndigoBlue.Velocity.dll
Represents a default value constraint that automatically assigns a value to a column when no value is specified during insert.
public class Default : Constraint, IEquatable<Constraint>, IComparable<Constraint>
- Inheritance
-
Default
- Implements
Examples
// Define a table with default value constraints
var table = new Table(schema, "orders");
table.AddColumn("id", DataType.Integer, autoIncrement: true);
table.AddColumn("customer_id", DataType.Integer);
table.AddColumn("order_date", DataType.DateTime);
table.AddColumn("status", DataType.VarChar, 20);
table.AddColumn("created_at", DataType.DateTime);
// Create default constraint for current timestamp on created_at
var defaultCreatedAt = new Default(
schema.Name,
"orders",
"created_at",
new Literal<DateTime>(DateTime.Now),
DefaultConstraintType.DateTime,
DataType.DateTime
);
// Create default constraint for status
var defaultStatus = new Default(
schema.Name,
"orders",
"status",
new Literal<string>("Pending"),
DefaultConstraintType.String,
DataType.VarChar
);
Remarks
Default constraints provide automatic values for columns, such as timestamps, sequential numbers, or constant values. They are applied when INSERT statements don't provide explicit values for the column.
Properties
- Column
Gets the name of the column that this default constraint applies to.
- ConstraintType
Gets the constraint type as Default.
- DataType
Gets the data type of the column.
- DefaultConstraintType
Gets the type of default constraint (String, Number, DateTime, Date, Timestamp, Boolean, or Guid).
- DefaultItem
Gets the default value item (can be a literal value, function call, or expression).
Methods
- GetColumnsForComparison()
Gets columns for comparison in a name-neutral way. Override in subclasses that have columns.
- IsEqual(Constraint)
Determines whether this constraint is equal to another constraint based on their properties.