Class Column
- Namespace
- YndigoBlue.Velocity.Model
- Assembly
- YndigoBlue.Velocity.dll
Represents a column in a database table.
public class Column : ISelectItem, IElement, ICheckItem, IGroupItem, IEquatable<Column>, IEquatable<string>, IComparable<Column>
- Inheritance
-
Column
- Implements
Examples
Adding columns to a table:
Table usersTable = schema.CreateTable("users");
// Auto-incrementing primary key
usersTable.AddColumn("user_id", DataType.Long, autoGenerate: true, notNull: true);
// Required text column with size limit
usersTable.AddColumn("username", DataType.VarChar, size: 100, notNull: true);
// Optional text column
usersTable.AddColumn("email", DataType.VarChar, size: 200);
// Numeric columns with precision and scale
usersTable.AddColumn("balance", DataType.Decimal, precision: 10, scale: 2);
// Integer column
usersTable.AddColumn("age", DataType.Integer);
// Date/time columns
usersTable.AddColumn("created_at", DataType.DateTime);
usersTable.AddColumn("birth_date", DataType.Date);
// Boolean column
usersTable.AddColumn("is_active", DataType.Boolean);
// Binary data column
usersTable.AddColumn("profile_image", DataType.VarBinary, size: 1048576); // 1MB
Referencing columns in queries:
Table usersTable = schema["users"];
// Access column by name
Column usernameColumn = usersTable["username"];
Column emailColumn = usersTable["email"];
Query query = new Query();
query.AddFromItem(usersTable);
query.AddSelectItem(usernameColumn);
query.AddSelectItem(emailColumn);
query.AddFilter(usersTable["age"], ConditionalType.GreaterThan, 18);
query.AddOrderClause(new OrderClause(usernameColumn, OrderClauseType.Ascending));
Using columns in constraints:
// Primary key
usersTable.AddPrimaryKey("pk_users", usersTable["user_id"]);
// Unique constraint
usersTable.AddUnique("uk_email", usersTable["email"]);
// Foreign key
ordersTable.AddForeignKey(
"fk_orders_users",
ordersTable["user_id"],
usersTable["user_id"]
);
// Check constraint
usersTable.AddCheck("ck_age", usersTable["age"], CheckOperator.GreaterThanOrEquals, 0);
Remarks
Columns define the structure of data within a table, specifying the data type, size constraints, nullability, and whether values are auto-generated.
Columns are created using AddColumn(string, DataType, bool, bool, int, byte, byte) or CreateColumn(string, DataType, bool, bool, int, byte, byte) methods, and can be referenced in queries, constraints, and indexes.
Fields
Properties
- CheckConstraintType
Gets the type of check constraint element.
- DataType
Gets the data type of the values returned by this select item.
- Name
Gets the name of the select item as it appears in the result set.
- Precision
Gets the precision for numeric data types.
- Scale
Gets the scale for numeric data types.
- SchemaName
Gets the name of the schema that contains the table this column belongs to.
- Size
Gets the maximum size for string or binary data types.
Methods
- CompareTo(Column)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
- Equals(string)
Indicates whether the current object is equal to another object of the same type.
- Equals(Column)
Indicates whether the current object is equal to another object of the same type.
- IsEqual(ICheckItem)
Determines whether this check item is equal to another check item.
- ToString()
Returns a string that represents the current object.