SQL to Drizzle Schema
Paste CREATE TABLE SQL and get a ready-to-use Drizzle ORM schema file. Choose the pg or mysql dialect and the converter emits the right table function, typed column helpers, .notNull(), .unique(), .primaryKey(), .references() for foreign keys, and the correct import line — no boilerplate hunting required.
How to use the SQL to Drizzle Schema
Paste one or more CREATE TABLE statements, pick a dialect (PostgreSQL or MySQL), and click Generate Schema. The output is a complete Drizzle schema file you can drop into your project.
- Dialect matters — PostgreSQL uses
pgTable,serial,varchar,timestamp, and imports fromdrizzle-orm/pg-core. MySQL usesmysqlTable,int().autoincrement(),varchar,datetime, and imports fromdrizzle-orm/mysql-core. - Foreign keys — REFERENCES clauses become
.references(() => otherTable.column)inline on the column; the referenced table must be defined first in your schema or imported. - Copy the output and save it as
schema.ts(orschema.js). Rundrizzle-kit generateto produce migrations from the new schema.
Note: the generated code uses named exports for each table (e.g. export const users = pgTable(...)). The import line at the top lists only the helpers actually used by your tables.
What is Drizzle ORM and why use a schema generator?
Drizzle ORM is a TypeScript-first relational query builder and ORM that keeps your database schema as the single source of truth. Unlike ActiveRecord-style ORMs that generate SQL from class definitions, Drizzle's schema files are the schema — typed column definitions that drive both compile-time type inference and the migration system (drizzle-kit). This means your TypeScript types and your database columns are always in sync without a separate type-generation step.
The schema file uses table helper functions (pgTable for PostgreSQL, mysqlTable for MySQL) and column helpers (serial, varchar, integer, boolean, timestamp, etc.) imported from the appropriate core package. Each column function is chainable: varchar('email', { length: 255 }).notNull().unique() reads almost like a column definition itself. Foreign key references use a callback .references(() => users.id) to avoid circular-import issues.
When you have an existing database — from a legacy app, a DBA hand-written migration, or a database design tool — you need to reverse-engineer the Drizzle schema before you can start using the ORM. Writing it by hand is tedious and error-prone. This converter does the mechanical translation, giving you a correct baseline that you can then customize (add indexes, rename columns, add relations objects) to suit your project.
Common use cases
- Adopting Drizzle on a live database — generate the initial schema file from your existing DDL without writing every column by hand.
- Switching from Prisma or TypeORM — export your schema as SQL DDL and convert it to the Drizzle equivalent in one step.
- Multi-dialect projects — maintain one DDL source and generate both pg and mysql variants for staging vs. production.
- Type-safe API layer — once the schema is in Drizzle, select queries return fully typed rows — no more
anyfrom raw SQL results. - Migration baseline — use the generated schema with
drizzle-kit pushto sync a fresh development database without writing explicit migrations.