SQL to Prisma Schema

Generate a Prisma schema model from a SQL CREATE TABLE statement.

SQL DDL Input
Prisma Schema Output
Prisma Schema output appears here

Related Tools

Documentation

What is SQL to Prisma?

SQL to Prisma reads one or more CREATE TABLE statements and generates a Prisma schema.prisma model block for each table — column types, primary keys, uniqueness, and defaults translated into Prisma's declarative field syntax.

How it works

The SQL is parsed into a structured table/column model (name, type, nullability, primary key, uniqueness, auto-increment, default expression, foreign key reference), then each column is mapped through a fixed type table — INTEGER/SERIALInt, VARCHAR/TEXTString, TIMESTAMPDateTime, UUIDString, and so on. A primary key becomes @id; SERIAL/AUTO_INCREMENT becomes @default(autoincrement()); a nullable, non-key column gets a trailing ?. Only a narrow, safe set of DEFAULT expressions is translated — numeric and string literals, booleans, and CURRENT_TIMESTAMP/NOW() (→ @default(now())). Anything else — a function call, an expression, a vendor-specific default — is emitted as a plain comment instead of a guessed Prisma attribute, and foreign keys are emitted as a comment noting the referenced table/column rather than a full @relation, since the relation's field name, array side, and cardinality aren't fully determined by the DDL alone.

Features

  • Multiple CREATE TABLE statements in one paste, each becoming its own model
  • snake_case columns renamed to camelCase Prisma fields
  • Primary key, unique, and nullable modifiers mapped to @id, @unique, and ?
  • Literal and now() defaults translated; anything else left as an honest comment
  • Copy or download the generated .prisma file

Example

Input:

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  external_id UUID DEFAULT uuid_generate_v4(),
  name VARCHAR(255) NOT NULL,
  is_active BOOLEAN DEFAULT true
);

CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  user_id INTEGER NOT NULL REFERENCES users(id),
  title VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Output:

model User {
  id  Int  @id @default(autoincrement())
  externalId  String?  // SQL default not translated: uuid_generate_v4()
  name  String
  isActive  Boolean?  @default(true)
}

model Post {
  id  Int  @id @default(autoincrement())
  userId  Int  // FK -> users.id
  title  String
  createdAt  DateTime?  @default(now())
}

Common errors

An unmapped DEFAULT expression like uuid_generate_v4() never gets fabricated into a Prisma attribute — it's dropped in as // SQL default not translated: uuid_generate_v4() so you notice and add the equivalent (often @default(uuid()) or @default(dbgenerated("uuid_generate_v4()"))) by hand. Foreign key columns similarly surface only as // FK -> table.column comments — the schema won't compile as a real relational Prisma schema until you add the matching @relation fields on both models yourself. CHECK constraints, generated columns, and partitioning clauses in the source SQL aren't modeled at all and are silently skipped.

Best practices

Treat the output as a first draft: run prisma format and prisma validate after pasting it in, then search for the two comment markers (SQL default not translated and FK ->) to find every spot that needs manual attention before you can run prisma migrate or db push against it.

Frequently Asked Questions

Does this generate the relation fields on both sides?

No — a foreign key column becomes a scalar field with a comment noting what it references (e.g. // FK -> users.id), not a full Prisma @relation on both models. Wiring the actual relation requires deciding field/array names and cardinality that aren't fully determined by the DDL alone, so that's left for you to add.

How are SERIAL / AUTO_INCREMENT columns handled?

Mapped to Int @id @default(autoincrement()) — Prisma's standard auto-incrementing primary key pattern.

What happens to a DEFAULT CURRENT_TIMESTAMP column?

It becomes @default(now()), Prisma's equivalent. Other SQL default expressions (functions, computed values) aren't translated — only literal defaults (numbers, strings, booleans) and CURRENT_TIMESTAMP/NOW() are recognized, since guessing at an arbitrary SQL function's Prisma equivalent risks being silently wrong.

Does it support multiple CREATE TABLE statements at once?

Yes — paste a whole schema dump and each table becomes its own model in the output.