Table of Contents

Class Unique

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

Represents a unique constraint that ensures all values in one or more columns are distinct.

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

Remarks

A unique constraint prevents duplicate values in the specified column(s). Unlike a primary key, a table can have multiple unique constraints, and unique columns can contain NULL values (depending on database).

Examples

using (var manager = new Manager(connection))
{
    var schema = manager.LoadSchema("myschema");
    Table table = schema.CreateTable("users");
    table.CreateColumn("id", DataType.Integer, autoGenerate: true);
    table.CreateColumn("username", DataType.VarChar, size: 50);
    table.CreateColumn("email", DataType.VarChar, size: 100);
    table.CreateColumn("phone", DataType.VarChar, size: 20);

    // Single-column unique constraint
    Unique uniqueUsername = table.CreateUniqueConstraint("uk_users_username", "username");

    // Composite unique constraint across multiple columns
    Unique uniqueContact = table.CreateUniqueConstraint("uk_users_contact", [ "email", "phone" ]);

    manager.CreateTable(table);
    manager.CreateConstraint(uniqueUsername);
    manager.CreateConstraint(uniqueContact);
}

Properties

Columns

Gets or sets the collection of column names that make up the unique constraint.

ConstraintType

Gets the constraint type as Unique.

Methods

IsEqual(Constraint)

Determines whether this constraint is equal to another constraint based on their properties.