SQL to Drizzle Schema
Convert SQL CREATE TABLE statements to Drizzle ORM schema definitions with type-safe column builders, relations, and indexes.
About This Tool
The SQL to Drizzle Schema converter is a free browser-based tool
that transforms SQL CREATE TABLE statements into
Drizzle ORM schema definitions. Drizzle ORM is a lightweight,
type-safe TypeScript ORM that uses a declarative schema-as-code
approach where your database tables are defined as plain
TypeScript objects. Instead of manually translating your
existing SQL database structure into Drizzle's schema format,
this tool automates the process and generates clean, idiomatic
Drizzle table definitions in seconds.
The converter parses your SQL and maps column types to their
Drizzle column builder equivalents. Standard SQL types like
VARCHAR, INTEGER, BOOLEAN,
TIMESTAMP, and JSON are all handled
automatically. It also recognizes database-specific types such as
PostgreSQL's SERIAL, UUID, and
JSONB, as well as MySQL's
AUTO_INCREMENT and TINYINT(1) boolean
pattern. The tool supports all three Drizzle dialect modules:
drizzle-orm/pg-core, drizzle-orm/mysql-core,
and drizzle-orm/sqlite-core.
Foreign keys are converted to Drizzle's .references()
chain method, pointing to the referenced table's column.
Composite primary keys become primaryKey() constraints
in the table's third argument, composite unique constraints
become unique().on(), and CREATE INDEX
statements are converted to index().on() calls.
Proper import statements are generated automatically based
on which column builders and constraint functions your
schema actually uses.
All processing happens entirely in your browser. Your SQL statements never leave your machine — there are no server round-trips, no logging, and no third-party services involved. This makes it safe to use with production database schemas and sensitive table definitions. The tool is ideal for migrating existing databases to Drizzle ORM, prototyping data models, or learning how SQL structures translate to Drizzle's schema-as-code paradigm.
How to Use
- Paste one or more SQL
CREATE TABLEstatements into the SQL Input panel on the left. - The Drizzle schema output updates automatically in the right panel as you type.
- Select your Dialect (PostgreSQL, MySQL, or SQLite) to ensure correct column builder mapping and import paths.
- Review the generated schema. The tool produces proper
importstatements, table definitions, column builders with chained modifiers, and constraint callbacks. - Click Copy or press Ctrl+Shift+C to copy the generated Drizzle schema to your clipboard.
- Use Sample to load an example SQL schema with multiple tables, foreign keys, and indexes.
- Click Clear to reset both panels and start fresh.
Popular SQL to Drizzle Examples
FAQ
Which SQL dialects are supported?
The parser supports standard SQL CREATE TABLE syntax and handles dialect-specific features from PostgreSQL, MySQL, and SQLite. This includes SERIAL / BIGSERIAL (PostgreSQL), AUTO_INCREMENT (MySQL), and AUTOINCREMENT (SQLite). Select the correct dialect in the dropdown to get the most accurate column builder mapping and import paths.
How are SQL types mapped to Drizzle column builders?
Common mappings include: VARCHAR to varchar(), INTEGER to integer(), BOOLEAN to boolean(), TIMESTAMP to timestamp(), TEXT to text(), JSON/JSONB to json()/jsonb(), SERIAL to serial(), UUID to uuid() (pg), BIGINT to bigint(), and DECIMAL/NUMERIC to numeric() or decimal(). Length and precision arguments are preserved.
How are foreign keys handled?
Both inline REFERENCES clauses and table-level FOREIGN KEY constraints are detected. The tool generates a .references(() => referencedTable.column) chain on the column builder. This follows Drizzle's recommended pattern for defining foreign key relationships.
Does it handle composite primary keys and indexes?
Yes. When the SQL defines a composite primary key via PRIMARY KEY (col1, col2), the tool generates a primaryKey() constraint in the table's third argument. Similarly, composite unique constraints and CREATE INDEX statements are converted to unique().on() and index().on() calls respectively.
Are import statements generated automatically?
Yes. The tool analyzes which column builders (varchar, integer, boolean, etc.) and constraint functions (primaryKey, unique, index) are used in your schema and generates the correct import statement from the dialect-specific module (drizzle-orm/pg-core, drizzle-orm/mysql-core, or drizzle-orm/sqlite-core). If SQL expressions are used in defaults, an additional import from drizzle-orm for the sql template tag is included.
Is my data safe?
Yes. All parsing and code generation runs entirely in your browser using JavaScript. No data is sent to any server. You can verify this by checking the Network tab in your browser's developer tools while using the tool.
How does this compare to the SQL to Prisma converter?
While both tools convert SQL to ORM schema definitions, they target different ORMs. Drizzle uses a schema-as-code approach with TypeScript functions and chained methods, while Prisma uses its own declarative schema language (.prisma files). Drizzle's schema is pure TypeScript, making it easier to compose programmatically and integrate with your existing TypeScript codebase.
Related Tools
SQL to Prisma Schema
Convert SQL CREATE TABLE statements to Prisma schema models. Supports common SQL types and relations.
SQL to Sequelize Model
Convert SQL CREATE TABLE statements to Sequelize model definitions with DataTypes mapping and associations.
SQL Formatter
Format, beautify, and minify SQL queries with dialect support for MySQL, PostgreSQL, and SQLite.
JSON to SQL Schema
Convert JSON to CREATE TABLE statements. Generate SQL schema for MySQL, PostgreSQL, and SQLite with automatic type inference.
SQL to MongoDB Query
Convert SQL SELECT statements to MongoDB find() and aggregate() queries with full clause support.
Prisma to SQL Schema
Convert Prisma schema models to SQL CREATE TABLE statements. Supports PostgreSQL, MySQL, and SQLite.