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