Skip to main content
Tables are the foundation of your database schema in Drizzle ORM. Each table is defined with columns and optional constraints like indexes, foreign keys, and checks.

Basic table definition

Table with constraints

Add indexes, foreign keys, and other constraints using the third parameter:
The third parameter must return an array of constraint builders, not an object. The object syntax is deprecated.

Column types function

Use the callback syntax to access column builders directly:
This provides autocomplete for all available column types without individual imports.

Custom table names

Create a table creator for custom prefixes:

Schema namespaces

PostgreSQL and MySQL support schema namespaces:

Row-level security (PostgreSQL)

Enable RLS on PostgreSQL tables:
Enabling RLS only adds the ENABLE ROW LEVEL SECURITY clause. You still need to define policies separately.

Complete example

API reference

string
required
The table name in the database
object | function
required
Column definitions as an object or callback function that receives column builders
function
Optional callback that receives the table columns and returns an array of constraints (indexes, foreign keys, etc.)