Table of Contents

Class PrimaryKey

Namespace
YndigoBlue.Velocity.Constraints
Assembly
YndigoBlue.Velocity.dll

Represents a primary key constraint that uniquely identifies each row in a table.

public class PrimaryKey : Constraint, IEquatable<Constraint>, IComparable<Constraint>
Inheritance
PrimaryKey
Implements

Examples

// Define a table with a single-column primary key
var table = new Table(schema, "users");
table.AddColumn("id", DataType.Integer, autoIncrement: true);
table.AddColumn("username", DataType.VarChar, 50);
table.AddColumn("email", DataType.VarChar, 100);

// Primary key is automatically created on 'id' column when autoIncrement is true

// Or create a composite primary key manually
var orderItemsTable = new Table(schema, "order_items");
orderItemsTable.AddColumn("order_id", DataType.Integer);
orderItemsTable.AddColumn("product_id", DataType.Integer);
orderItemsTable.AddColumn("quantity", DataType.Integer);

// Composite primary key on both order_id and product_id
var pk = new PrimaryKey("pk_order_items", schema.Name, "order_items",
    new[] { "order_id", "product_id" });

Remarks

A primary key constraint enforces uniqueness and non-null values for one or more columns. Each table can have only one primary key, which can be either single-column or composite (multiple columns).

Properties

Columns

Gets or sets the collection of column names that make up the primary key.

ConstraintType

Gets the constraint type as PrimaryKey.

IsComposite

Gets whether this is a composite primary key (spanning multiple columns).

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.