01What is Prisma to SQL?
If you need to see the DDL behind a Prisma schema, or hand it to a DBA who doesn't use Prisma, paste the schema here and pick a dialect. The output follows the conventions Prisma's own migrate engine uses, and it was compared line by line with prisma migrate diff for the bundled examples. PostgreSQL, MySQL and SQLite each have their own type map: String becomes TEXT on Postgres and SQLite and VARCHAR(191) on MySQL, DateTime becomes TIMESTAMP(3), DATETIME(3) or DATETIME, Decimal DECIMAL(65,30), Json JSONB or JSON, and so on, while @db.Text, @db.VarChar(n), @db.Decimal(p, s), @db.Uuid and similar native-type attributes override the defaults. Table names are the model name unless @@map renames them, and column names follow @map. @id and composite @@id become a named primary key constraint (Model_pkey), autoincrement() becomes SERIAL, AUTO_INCREMENT or SQLite's INTEGER PRIMARY KEY AUTOINCREMENT, required fields get NOT NULL, and defaults for now(), booleans, numbers, quoted strings (escaped safely), enum values and dbgenerated() are carried over. cuid() and uuid() get no database default because Prisma Client generates those values. @unique and @@unique become CREATE UNIQUE INDEX Model_field_key, and @@index becomes CREATE INDEX Model_field_idx. Each @relation(fields, references) becomes a FOREIGN KEY with Prisma's default actions (ON DELETE RESTRICT, or SET NULL for optional relations, ON UPDATE CASCADE) unless onDelete or onUpdate say otherwise; on Postgres and MySQL these are added with ALTER TABLE after all tables exist, and on SQLite they are written inside CREATE TABLE. Enums turn into CREATE TYPE on Postgres, inline ENUM(...) on MySQL and TEXT on SQLite. Scalar lists like String[] become arrays on Postgres and are skipped with a note elsewhere, as Prisma doesn't support them there either. A relation to a model you didn't paste is reported in a comment instead of producing a broken reference. Everything is converted in your browser with pattern matching, so views, multi-schema setups and Prisma's MySQL table options are not reproduced.
Backend developers, database administrators, and teams moving between Prisma and plain SQL migrations. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Prisma to SQL
- Choose PostgreSQL, MySQL or SQLite from Dialect.
- Paste your schema into Prisma Schema; output updates as you type.
- Review the SQL Output and any error message.
- Click Copy SQL to take the DDL.
03Worked examples
- Input:
model User { id Int @id @default(autoincrement()); email String @unique; name String?; createdAt DateTime @default(now()) } (PostgreSQL) - Result:
CREATE TABLE "User" ( "id" SERIAL NOT NULL, "email" TEXT NOT NULL, "name" TEXT, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "User_pkey" PRIMARY KEY ("id") ); CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); - @unique becomes a separate unique index named Model_field_key, the same naming Prisma Migrate uses.
- Input:
Same User model (MySQL) - Result:
CREATE TABLE `User` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `email` VARCHAR(191) NOT NULL, `name` VARCHAR(191), `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), CONSTRAINT `User_pkey` PRIMARY KEY (`id`) ); CREATE UNIQUE INDEX `User_email_key` ON `User`(`email`); - String maps to VARCHAR(191) on MySQL, which is Prisma's default length for that database.
- Input:
Same User model (SQLite) - Result:
CREATE TABLE "User" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT, "email" TEXT NOT NULL, "name" TEXT, "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); - SQLite only allows AUTOINCREMENT on an INTEGER PRIMARY KEY column, so the primary key is declared on the column instead of as a separate constraint.
- Input:
enum Role { USER ADMIN } model Account { id String @id @default(uuid()); role Role @default(USER) } (PostgreSQL) - Result:
CREATE TYPE "Role" AS ENUM ('USER', 'ADMIN'); CREATE TABLE "Account" ( "id" TEXT NOT NULL, "role" "Role" NOT NULL DEFAULT 'USER', CONSTRAINT "Account_pkey" PRIMARY KEY ("id") ); - There is no SQL default for id because Prisma creates uuid() values in the client.
- Input:
Same enum schema (MySQL) - Result:
CREATE TABLE `Account` ( `id` VARCHAR(191) NOT NULL, `role` ENUM('USER', 'ADMIN') NOT NULL DEFAULT 'USER', CONSTRAINT `Account_pkey` PRIMARY KEY (`id`) ); - MySQL has no CREATE TYPE, so the enum values are written inline on the column.
04Common use cases
- Reviewing the tables Prisma would create before running a migration on a shared database
- Giving a DBA readable DDL for a schema review
- Seeding a SQLite test database without the Prisma CLI
- Porting a Prisma project to raw SQL migrations with Flyway or golang-migrate
- Comparing how the same model looks in PostgreSQL versus MySQL
05Tips
- Paste every model a relation points to; otherwise that foreign key is left out and a comment tells you which one.
- Columns with @default(cuid()) or @default(uuid()) have no database default, so raw SQL inserts must supply the id themselves.
- Run prisma migrate diff --from-empty --to-schema-datamodel when you need Prisma's exact output to compare against.
- On SQLite, foreign keys are only enforced after PRAGMA foreign_keys = ON.
06Related concepts
SQL DDL, Prisma schema, PostgreSQL, MySQL, SQLite, Database migrations.
Frequently Asked Questions
What is Prisma to SQL?
Prisma to SQL is a free, browser-based developer tool on AIDToolStack. Convert Prisma schema to SQL DDL It requires no installation or sign-up and works entirely in your browser.
Is Prisma to SQL free to use?
Yes. No sign-up, no fees and no usage cap.
Does Prisma to SQL store my data?
No. It runs in your browser; nothing is uploaded.