SQL to Prisma Schema with Relations

Convert SQL CREATE TABLE statements to Prisma schema with automatic relation generation. Supports foreign keys, one-to-many, and one-to-one relationships.

What is SQL to Prisma Schema with Relations?

This tool converts SQL CREATE TABLE statements into Prisma schema definitions with automatic relation generation. Prisma is a modern database toolkit that includes an ORM, migrations system, and database client. The converter automatically detects foreign key relationships and generates proper @relation annotations with bidirectional relations.

How to Use

  1. Paste your SQL CREATE TABLE statements into the input area
  2. Click "Generate" to create the Prisma schema
  3. Review the generated models with automatic relations
  4. Copy the output and save it as schema.prisma in your Prisma project

Why Use This Tool?

Automatically map SQL types to Prisma scalar types
Generate bidirectional relations from foreign keys
Handle one-to-many (parent children[]) and one-to-one (parent profile?) relations
Support PRIMARY KEY, NOT NULL, DEFAULT, UNIQUE constraints
Detect unique foreign keys for one-to-one relationships

Tips & Best Practices

  • Foreign keys with UNIQUE constraint generate one-to-one relations (Profile?)
  • Regular foreign keys generate one-to-many relations (Post[])
  • SERIAL types are mapped to Int @id @default(autoincrement())
  • Table names are converted to PascalCase model names
  • Add @@index([]) manually for composite indexes

Frequently Asked Questions

What is Prisma?

Prisma is a modern database toolkit that includes an ORM (Prisma Client), migrations system, and a declarative data modeling language. It supports PostgreSQL, MySQL, SQLite, SQL Server, MongoDB, and CockroachDB.

How are relations generated?

The tool analyzes REFERENCES constraints in your SQL and generates Prisma @relation annotations. For each foreign key, it creates the relation field on the referencing model and the reverse relation field (array or optional) on the referenced model.

How does one-to-one vs one-to-many work?

If a foreign key column has a UNIQUE constraint, the tool generates a one-to-one relation (Profile?). Otherwise, it generates a one-to-many relation (Post[]).

What SQL types are supported?

The tool supports common SQL types including INTEGER, BIGINT, VARCHAR, TEXT, BOOLEAN, TIMESTAMP, DATE, JSON, UUID, DECIMAL, FLOAT, and more. Unsupported types default to String.

Is my SQL data sent to a server?

No, all processing happens entirely in your browser. Your SQL schema never leaves your device.

Related Tools