Code converters

SQL to Prisma Schema Converter

Paste SQL DDL and get a schema.prisma with models, native database types, relations on both sides, enums and indexes, without connecting to your database.

  • Free foreverNo trial, no paywall, no usage limits.
  • No sign-upOpen the page and start. We never ask for an email to use a tool.
  • PrivateEverything runs in your browser. Your input is never uploaded or stored on our servers.
  • Works offlineOnce the page has loaded, the tool keeps working without a connection.
Source databaseThe SQL dialect of your DDL. It decides how quotes, types and auto-increment are read, and which ORM column types you get.
PostgreSQL, Supabase, Neon and pg_dump output.MySQL, MariaDB and PlanetScale, including mysqldump and phpMyAdmin exports.SQLite, Turso (libSQL) and Cloudflare D1, including sqlite3 .schema output.

SQL schema (DDL)

Reads tables, indexes, enum types, domains, comments and constraints added later with alter table. Drop a .sql file onto the editor to open it.
Clear

schema.prisma

CopyDownload schema.prisma
Paste table definitions, a pg_dump or a mysqldump. Nothing leaves your browser.

Need this built into your own API or pipeline? Talk to our team

Quick answer

To convert SQL to a Prisma schema, turn each CREATE TABLE into a model, each column into a field with a Prisma scalar type and an @db native type, and each foreign key into a pair of relation fields. Playxoft's free SQL to Prisma Converter does this in your browser: paste PostgreSQL, MySQL or SQLite DDL and it writes schema.prisma with @id, @unique, @@index, enums and @map, in the same style prisma db pull produces.

  • PostgreSQL, MySQL and SQLite
  • Native @db types
  • Relations on both sides
  • Enums with @map
  • Prisma 6 and 7 headers
  • @map and @@map naming
  • Line-numbered notes

How to use the SQL to Prisma Converter

  1. 1Choose your Source database: PostgreSQL, MySQL or SQLite.
  2. 2Paste your CREATE TABLE statements, drop a .sql dump onto the editor, or click Load example.
  3. 3Pick Naming: Prisma style for PascalCase models and camelCase fields mapped to your SQL names, or Keep SQL names.
  4. 4Choose your Prisma version for the generator and datasource blocks, or turn them off to paste models into an existing schema.
  5. 5Review the Notes, then copy or download schema.prisma and run npx prisma validate and npx prisma generate.

How are SQL types mapped to Prisma?

Prisma has a small set of scalar types (String, Int, BigInt, Float, Decimal, Boolean, DateTime, Json, Bytes). The exact database type is kept with a native type attribute such as @db.VarChar(255), so migrations recreate the same column:

SQL typePrisma fieldPostgreSQL attributeMySQL attribute
integer / intIntnonenone
bigintBigIntnone@db.UnsignedBigInt if unsigned
serial / AUTO_INCREMENTInt @default(autoincrement())nonenone
varchar(255)String@db.VarChar(255)@db.VarChar(255)
textStringnone@db.Text
boolean / tinyint(1)Booleannonenone
timestamptzDateTime@db.Timestamptz(6)not available
timestampDateTime@db.Timestamp(6)@db.Timestamp(0)
datetime (MySQL)DateTimen/a@db.DateTime(0)
numeric(10,2)Decimal@db.Decimal(10, 2)@db.Decimal(10, 2)
json / jsonbJson@db.Json / nonenone
uuidString@db.Uuidnot available
bytea / blobBytesnone@db.Blob
tsvector, interval…Unsupported("…")n/an/a

Why @db.Timestamptz(6)? Prisma's default DateTime column is timestamp(3) (millisecond precision), while PostgreSQL defaults to 6 digits. Writing the precision explicitly stops prisma migrate from quietly changing your columns. SQLite has no native type attributes, so its fields are plain scalars.

How are foreign keys turned into Prisma relations?

Every foreign key becomes two fields. The model that holds the key gets a relation field with @relation(fields: […], references: […]); the referenced model gets a list field pointing back:

model Post {
  id       Int  @id @default(autoincrement())
  authorId Int  @map("author_id")
  author   User @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate: NoAction)

  @@map("posts")
}

model User {
  id    Int    @id @default(autoincrement())
  posts Post[]
}

If the foreign key columns are unique, the relation is one-to-one and the back field is optional (profile Profile?). When two models are linked more than once, or a table references itself, each relation gets a name such as @relation("EmployeeManager"), which Prisma requires to tell them apart.

Referential actions are written only when your SQL differs from Prisma's defaults: Prisma assumes onDelete: Restrict for required relations, SetNull for optional ones and onUpdate: Cascade. SQL without an ON UPDATE clause means NO ACTION, so the converter writes onUpdate: NoAction to keep your existing behavior instead of letting a later migration change it.

Should I use prisma db pull or this converter?

prisma db pull introspects a live database and is the most exact option when you can connect to it. This converter produces the same kind of schema from SQL text, which is faster when:

  • you only have a migration file, a schema dump or a snippet from documentation;
  • the database is not reachable from your machine, or you do not want to hand over credentials;
  • you want to convert a single table, or try naming options and see the result instantly;
  • you are moving a project from raw SQL or another ORM and want a starting schema.prisma before any database exists.

Use prisma db pull when you need views, @@ignore decisions made against real data, or extensions Prisma detects at runtime. Either way, run npx prisma validate on the result before generating a client.

How should Prisma models and fields be named?

Prisma's convention is PascalCase, singular model names (User, OrderItem) and camelCase field names (createdAt), while SQL databases usually use plural snake_case (order_items.created_at). You do not have to choose: @map and @@map keep the database names while your TypeScript uses Prisma names.

model OrderItem {
  orderId   Int     @map("order_id")
  unitPrice Decimal @map("unit_price") @db.Decimal(10, 2)

  @@id([orderId, sku])
  @@map("order_items")
}

Choose Prisma style in Naming for this, or Keep SQL names to mirror the tables exactly, as prisma db pull does. Constraint names follow the same idea: Prisma expects users_pkey, users_email_key, users_email_idx and posts_author_id_fkey, so a map: argument is added only when your SQL uses a different name. Enum values that are not valid identifiers, such as in-progress, become in_progress @map("in-progress").

What can Prisma not represent?

Some SQL has no Prisma equivalent. Instead of failing, the converter keeps a valid schema and explains each case in the Notes panel:

  • Tables without a primary key or unique column are marked @@ignore, exactly like prisma db pull does, because Prisma Client needs a unique identifier per row.
  • Types without a Prisma scalar (tsvector, interval, PostGIS geometry, MySQL SET) become Unsupported("…") fields, readable through raw queries.
  • Partial and expression indexes and CHECK constraints are left as comments; keep them in a SQL migration.
  • Generated columns become plain fields with a comment, since Prisma cannot mark a column as computed.

Need the same schema in TypeScript instead? The SQL to Drizzle converter reads the same input.

Frequently asked questions

No. It reads the SQL you paste and builds the Prisma schema in your browser. There is no connection string, no upload and no logging, so it is safe for production dumps.
Your SQL did not say what happens on update, which means NO ACTION in the database, while Prisma's own default is Cascade. Writing NoAction keeps your current foreign keys unchanged when you later run prisma migrate. Delete it if you want Prisma's default.
dbgenerated keeps the default in the database, so rows inserted by any client get a UUID. uuid() is generated by Prisma Client, so only inserts made through Prisma get one. Turn on uuid() defaults if Prisma is the only writer.
Prisma Client needs a primary key or a required unique column to identify each row. Tables without one are kept in the schema for migrations but ignored by the client. Add a primary key to the table to use it from Prisma.
Yes. With Prisma version 7 selected, the generator uses the prisma-client provider with an output path and the datasource leaves the connection URL to prisma.config.ts. Choose 6 for the prisma-client-js generator with url = env("DATABASE_URL").
Yes. Data rows, SET statements and psql commands are skipped, and constraints added later with ALTER TABLE are applied to the right model. Views, functions and triggers are listed in the notes as skipped.

Last updated by the Playxoft engineering team.

From the engineers who built this tool

Fighting messy data every day?

When payloads, schemas and integrations keep breaking, the fix is usually upstream. We design typed APIs and backends that stay clean as you grow. Tell us what you are building and we will suggest the simplest architecture that fits.

More free tools

See all tools

SQL Formatter

Beautify or minify SQL in 12 dialects, with keyword case, indent and line:column errors.

Open tool

cURL to Python Converter

New

Convert cURL commands into Python requests or httpx code with params, json, files and auth.

Open tool

cURL to Fetch Converter

New

Turn any cURL command into JavaScript fetch() code with headers, JSON, forms and auth.

Open tool

cURL to Axios Converter

New

Convert cURL commands into an Axios request config with params, data, auth and timeouts.

Open tool

SQL to Drizzle Converter

Turn SQL DDL into a typed Drizzle schema.ts with indexes, enums and relations().

Open tool

SVG to JSX Converter

Turn SVG markup or files into clean React and React Native components.

Open tool