Introducing DBML Check Constraints — Enforce Data Rules with Ease

Great news! We’ve added support for Check constraints, allowing you to set rules on your table fields to enforce data quality—such as ensuring quantities are above zero or ratings stay within a range.

Here’s a simple DBML example:

Table orders {
  id integer [pk, increment]
  price decimal [not null, check: `price > 0`]
  discount decimal [not null, default: 0, check: `discount >= 0`]

  checks {
    `discount < price` [name: 'valid_discount']
  }
}

Previously, these had to go in notes, which meant they could disappear during SQL imports or exports. Now, define them right in DBML, import and export with accuracy, and view them in your ER diagrams and docs for clearer sharing.


It's a simple way to make your databases more reliable and your documentation more informative. Update your diagrams now and start applying `Check` constraints!

:books: Read the full docs →

If you have any feedback for us, feel free to reply in this post.
From dbx team with :heart:

You can also use Check constraints to validate table field values in RunSQL. :point_right: Check the query here


Happy to see this new feature !

I’ve personnaly a request about it :
Is it possible to make it work with enums ? like something like this :

enum my_enum {
  value1,
  value2
}
field varchar [check: my_enum]

and it generate

field varchar CHECK(field in ('value1', 'value2'))

It can be very usefull to factorize some

Hi @Matteo_Convert ,

Thank you for the enum check suggestion. We’ll consider it in the future.

In the meantime, have you tried using the enum type directly as a field’s type to see if it works for you? For example:

enum my_enum {
  value1
  value2
}

table a {
field my_enum
}