> ## Documentation Index
> Fetch the complete documentation index at: https://docs.standardcomputers.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Standard Definitions: Enumerations for Constraints

> Learn how to define Standard definitions (enumerations) and use them as constraint types to enforce a fixed set of allowed values.

Standard definitions are a special type of Standard that act as enumerations. You use them when a field in your data should only ever hold one of a fixed set of known values — for example, a status, a category, or a color. By defining the allowed values once in a Standard definition, you enforce them automatically every time a record is created or updated.

## Defining a Standard Definition

A Standard definition uses the `def` keyword to declare each allowed value. The syntax mirrors a regular Standard but contains `def` entries instead of typed constraints:

```stds theme={null}
color: CLR {
    def red "RED"
    def orange "ORANGE"
    def yellow "YELLOW"
    def green "GREEN"
    def blue "BLUE"
    def indigo "INDIGO"
    def violet "VIOLET"
}
```

Each `def` entry maps a name (e.g. `red`) to a string value (e.g. `"RED"`). The name is what you use in code; the value is what gets stored in the record.

## Using a Standard Definition as a Constraint

Reference a Standard definition in another Standard using the `standard` type and the `@` prefix on the definition's reference:

```stds theme={null}
vehicle: VHL {
    private vin string VN *
    protected make string MK *
    protected model string MDL *
    protected type standard @CLR clr
}
```

When a value is passed to the `vehicle` Standard for the `type` constraint, the system validates that it matches one of the values defined in the `color` Standard definition. Any value that does not match will be rejected before the record is saved.

<Note>
  Standard definitions enforce their allowed values at write time. If you add or remove a `def` entry from a Standard definition, existing records are not retroactively updated — only new writes are validated against the updated definition.
</Note>

## Creating Records with Standard Definitions

When you use a Standard definition in a creation query, you have three equivalent ways to supply the value — use whichever is most readable in context:

```stds theme={null}
#Create red vehicles
[vehicle] + ("VIN173", "Dodge", "Durango", red)
[vehicle] + ("VIN453", "Dodge", "Durango", "RED")
[vehicle] + ("VIN189", "Dodge", "Durango", @CLR.red)
```

The same flexibility applies to delete and find queries:

```stds theme={null}
#Delete red vehicles
[vehicle] - <color CLR.red>
[vehicle] - <color "RED">
[vehicle] - <color red>

#Find 5 red vehicles
[vehicle] <color @CLR.red, LIMIT 5>
```

<Tip>
  Using the `@CLR.red` form is the most explicit option and makes it immediately clear to anyone reading the query that `color` is a Standard definition constraint rather than a plain string field. Prefer it in shared or production code.
</Tip>
