Prisma to SQL Schema

Convert Prisma schema model definitions to SQL CREATE TABLE statements with type mapping, foreign keys, and indexes.

About This Tool

The Prisma to SQL converter is a free browser-based tool that transforms Prisma schema model definitions into SQL CREATE TABLE statements. Prisma is a widely-used type-safe ORM for Node.js and TypeScript, and its declarative schema language makes data modeling intuitive. However, when you need the raw SQL equivalent — for database migrations, documentation, or working with teams that don't use Prisma — this tool bridges the gap instantly.

The converter parses your Prisma model blocks and maps each field type to the appropriate SQL column type for your chosen dialect. Prisma types like String, Int, Float, Boolean, DateTime, Json, BigInt, Decimal, and Bytes are all mapped correctly. It handles @id (primary key), @default(autoincrement()) (serial / auto-increment), @unique, @map (column renaming), and @@map (table renaming). If you need the reverse direction, use the companion SQL to Prisma converter.

Relations defined with @relation are converted to FOREIGN KEY constraints with the correct column and table references. Composite keys from @@id become composite PRIMARY KEY clauses, @@unique becomes composite UNIQUE constraints, and @@index becomes CREATE INDEX statements. Prisma enum definitions are translated to CREATE TYPE ... AS ENUM for PostgreSQL or inline ENUM(...) for MySQL.

All processing runs entirely in your browser — your schema never leaves your machine. No server requests, no logging, no third-party services. This makes it safe to use with production schemas and sensitive model definitions. The tool supports PostgreSQL, MySQL, and SQLite dialects with dialect-specific syntax differences handled automatically.

For related conversions, check out JSON to SQL for generating INSERT statements from JSON data, or JSON to SQL Schema for inferring table structures from JSON objects.

How to Use

  1. Paste your Prisma schema model and enum definitions into the Prisma Schema Input panel on the left.
  2. The SQL output updates automatically in the right panel as you type.
  3. Select your target SQL Dialect (PostgreSQL, MySQL, or SQLite) to get dialect-specific syntax.
  4. Click Sample to load an example Prisma schema with models, relations, enums, and indexes.
  5. Review the generated CREATE TABLE, CREATE TYPE, and CREATE INDEX statements in the output.
  6. Click Copy or press Ctrl+Shift+C to copy the generated SQL to your clipboard.
  7. Click Clear to reset both panels and start fresh.

Popular Prisma to SQL Examples

View all Prisma to SQL examples →

FAQ

Which SQL dialects are supported?

The tool supports PostgreSQL, MySQL, and SQLite. Each dialect produces correct syntax for its target database. For example, PostgreSQL uses SERIAL for auto-increment and CREATE TYPE for enums, MySQL uses AUTO_INCREMENT and inline ENUM(), and SQLite uses INTEGER PRIMARY KEY AUTOINCREMENT.

How are Prisma types mapped to SQL types?

Common mappings include: String to VARCHAR(255), Int to INTEGER, BigInt to BIGINT, Float to DOUBLE PRECISION (PostgreSQL) or DOUBLE (MySQL), Decimal to DECIMAL(10,2), Boolean to BOOLEAN, DateTime to TIMESTAMP (PostgreSQL/SQLite) or DATETIME (MySQL), Json to JSONB (PostgreSQL) or JSON (MySQL), and Bytes to BYTEA (PostgreSQL), LONGBLOB (MySQL), or BLOB (SQLite).

How are Prisma relations converted to SQL?

Fields with @relation(fields: [...], references: [...]) are converted to FOREIGN KEY constraints. The tool reads the local field names and referenced model field names, maps them to their SQL column names (accounting for @map annotations), and generates FOREIGN KEY (local_col) REFERENCES ref_table (ref_col) constraints.

How are Prisma enums handled?

Prisma enum blocks are converted to CREATE TYPE ... AS ENUM (...) statements for PostgreSQL. For MySQL, enum values are used as inline ENUM(...) column types. SQLite has no native enum support, so TEXT columns with CHECK constraints are generated instead.

Does it handle @map and @@map annotations?

Yes. When a field has @map("column_name"), the specified name is used as the SQL column name. When a model has @@map("table_name"), that name is used as the SQL table name. If no mapping is specified, the tool converts PascalCase model names to snake_case table names and camelCase field names to snake_case column names.

Is my data safe?

Yes. All parsing and SQL 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.

Can I convert multiple models at once?

Yes. Paste your entire Prisma schema with multiple model and enum definitions, and the tool will generate a CREATE TABLE statement for each model and CREATE TYPE / ENUM for each enum. Relations between models are converted to FOREIGN KEY constraints with correct cross-table references.

Related Tools