01What is SQL to Prisma?
You have a SQL file full of CREATE TABLE statements and you want Prisma models. Maybe the database lives somewhere you can't reach, or the schema only exists in a design doc. Paste the SQL and the Prisma Schema panel fills in as you type. Each table becomes a model with a PascalCase name plus an @@map pointing at the real table. Prisma's schema reference says a model maps to a table of the same name unless you add @@map, so this keeps queries aimed at the right place. Columns become camelCase fields, with @map whenever the original name differs. Common MySQL, PostgreSQL and SQLite types map onto Prisma's scalar types: Int, BigInt, Float, Decimal, String, Boolean, DateTime, Json and Bytes. Anything the parser doesn't recognise falls back to String. A column without NOT NULL becomes optional, even when it has a default. Keys get the same care. A column or table-level PRIMARY KEY becomes @id, and a composite one becomes @@id([...]). AUTO_INCREMENT, SERIAL and identity columns get @default(autoincrement()). NOW() and CURRENT_TIMESTAMP become @default(now()), and gen_random_uuid() becomes @default(uuid()). MySQL's ON UPDATE CURRENT_TIMESTAMP adds @updatedAt. Other default expressions are wrapped in dbgenerated() so nothing quietly disappears. Foreign keys, written as FOREIGN KEY ... REFERENCES or inline REFERENCES, add a relation field on both models, since Prisma requires both sides. Relations get names when one table points at another twice or at itself. A quick example: an order_items table with order_id, product_id, qty INT NOT NULL DEFAULT 1 and PRIMARY KEY (order_id, product_id) comes out as model OrderItems with orderId and productId mapped back to their snake_case columns, qty Int @default(1), and @@id([orderId, productId]). A table with no primary key or unique column gets @@ignore and a comment, matching what prisma db pull does. A foreign key pointing at a table you didn't paste stays a plain scalar with a comment explaining why. Some things are skipped on purpose. Composite foreign keys, ON DELETE actions, enums, indexes, views and native type details like VARCHAR(255) are not converted. Your SQL is parsed in the page itself and never uploaded. Treat the output as a solid first draft, then run npx prisma validate before you migrate.
Backend developers moving an existing SQL schema into Prisma who want a first draft of their models without connecting to the database. The tool runs entirely in your browser, so your data never leaves your device.
02How to use SQL to Prisma
- Paste one or more CREATE TABLE statements into SQL Input, or load the Users Table, Blog Schema or E-Commerce example.
- Read the Prisma Schema panel. The toolbar shows how many models were generated.
- Look for comments in the output, such as a reference to a table you didn't paste or a table marked @@ignore.
- Click Copy Prisma and paste the models below the datasource block in schema.prisma.
- Run npx prisma validate, then add onDelete actions and @db native types where you need them. Use Reset to clear the input.
03Worked examples
- Input:
CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); - Result:
model Users { id Int @id @default(autoincrement()) email String @unique createdAt DateTime? @default(now()) @map("created_at") @@map("users") } - created_at becomes optional (DateTime?) because the column has no NOT NULL, even though it has a default.
- Input:
CREATE TABLE prices (sku VARCHAR(20) PRIMARY KEY, amount DECIMAL(10,2), meta JSONB); - Result:
model Prices { sku String @id amount Decimal? meta Json? @@map("prices") } - Length and precision such as VARCHAR(20) and DECIMAL(10,2) aren't carried over as @db attributes; add them by hand if you need them.
- Input:
CREATE TABLE users (id INT PRIMARY KEY, name TEXT); CREATE TABLE posts (id INT PRIMARY KEY, user_id INT NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id)); - Result:
model Users { id Int @id name String? posts Posts[] @@map("users") } model Posts { id Int @id userId Int @map("user_id") user Users @relation(fields: [userId], references: [id]) @@map("posts") } - Input:
CREATE TABLE blog_posts ( id SERIAL PRIMARY KEY, author_id INT NOT NULL REFERENCES users(id), title TEXT NOT NULL, published BOOLEAN DEFAULT false ); - Result:
model BlogPosts { id Int @id @default(autoincrement()) authorId Int @map("author_id") title String published Boolean? @default(false) // author_id references users(id), which isn't in the pasted SQL, so no relation field was added @@map("blog_posts") } - A relation field is only added when the referenced table is in the pasted SQL too.
- Input:
CREATE TABLE order_items (order_id INT NOT NULL, product_id INT NOT NULL, qty INT NOT NULL DEFAULT 1, PRIMARY KEY (order_id, product_id)); - Result:
model OrderItems { orderId Int @map("order_id") productId Int @map("product_id") qty Int @default(1) @@id([orderId, productId]) @@map("order_items") } - A table-level composite PRIMARY KEY becomes @@id with the camelCase field names.
- Input:
CREATE TABLE audit_log (msg TEXT, at TIMESTAMP); - Result:
model AuditLog { msg String? at DateTime? // This table has no primary key or unique column; Prisma Client can't use it until you add one @@ignore @@map("audit_log") } - Without any primary or unique key the model gets @@ignore, the same thing prisma db pull does.
04Common use cases
- Starting a Prisma schema from a schema.sql file checked into an older project
- Converting CREATE TABLE examples from a tutorial or blog post into Prisma models
- Drafting models when prisma db pull can't reach the database, for example a locked-down production server
- Checking how a FOREIGN KEY turns into relation fields on both models before you write queries
- Moving a small SQLite app to Prisma by pasting the output of .schema
- Spotting tables with no primary key, which Prisma marks with @@ignore, before you plan a migration
05Tips
- If you can connect to the database, prisma db pull is still the most accurate route. This tool shines when all you have is SQL text.
- Paste every related table together. A relation field only appears when the referenced table is in the same input.
- Rename generated back-relation fields like posts or messagesSender freely. Field names live in Prisma only and never touch the database.
- Add @db.VarChar(255) or @db.Decimal(10, 2) by hand if your migrations need the exact native column types.
- A nullable created_at with a default still becomes DateTime?. Add NOT NULL in your SQL first if the column should be required.
06Related concepts
Prisma schema, ORM, Database migration, Introspection.
Frequently Asked Questions
What is SQL to Prisma?
SQL to Prisma is a free, browser-based developer tool on AIDToolStack. Convert SQL CREATE TABLE statements to Prisma schema models. It requires no installation or sign-up and works entirely in your browser.
Is SQL to Prisma free to use?
Yes. No sign-up, no fees and no usage cap.
Does SQL to Prisma store my data?
No. It runs in your browser; nothing is uploaded.