Skip to tool

SQL to Prisma Schema

SQL to Prisma Schema tool on AzWebTools.

Result

Fill inputs and click run.

How to Use This Tool

  1. Select your source database dialect (e.g., PostgreSQL, MySQL) from the dropdown menu.
  2. Paste your raw SQL DDL statements (like CREATE TABLE) into the input area.
  3. Click the conversion button to process the SQL.
  4. Copy the generated Prisma models from the output area.
  5. Paste the models directly into your schema.prisma file.

Learn More About SQL to Prisma Schema

What is Prisma?

Prisma is an open-source Object-Relational Mapper (ORM) for Node.js and TypeScript. It utilizes a custom schema definition language (schema.prisma) to define data models, which are then used to generate a type-safe database client (Prisma Client). This declarative approach offers an intuitive developer experience, bridging the gap between relational databases and modern application code.

Why Convert SQL to Prisma Schema?

While developers typically use prisma db pull (introspection) to generate a schema from a live database, there are scenarios where connecting to a live database isn't practical:

  • Offline Prototyping: Instantly draft a Prisma setup using exported SQL scripts or DDL snippets without spinning up a local database instance.
  • Migration Planning: Visualize how legacy SQL tables map to Prisma models to assist in architecture and migration planning.
  • Learning & Debugging: Understand how standard SQL data types (like VARCHAR, TIMESTAMP, or ENUM) translate into Prisma's scalar types (String, DateTime, or enum).

Common SQL to Prisma Data Type Mappings

When translating SQL DDL to Prisma syntax, standard database types are mapped to Prisma's scalar types. Common conversions include:

  • INT, SERIALInt
  • VARCHAR, TEXTString
  • BOOLEANBoolean
  • TIMESTAMP, DATETIMEDateTime
  • DECIMAL, NUMERICDecimal

SQL constraints are also translated into Prisma attributes. For instance, a PRIMARY KEY becomes @id, a UNIQUE constraint maps to @unique, and default values are applied using @default().

The Origin of Prisma Schema

Prisma was developed to solve complex data access patterns in modern backend development, particularly within the Node.js and TypeScript ecosystems. The Prisma Schema Language (PSL) was introduced as a declarative way to model data, acting as the single source of truth for database schema migrations and generated type-safe query clients. It bridges the gap between traditional SQL database management and modern application code.
Prisma introduced a declarative schema language to simplify database access and ensure type safety in Node.js and TypeScript applications.
Language
Prisma Schema Language (PSL)
Primary Ecosystem
Node.js, TypeScript
File Extension
.prisma

Examples

Basic User Table

Runtime-verified example for sql-to-prisma-schema
Input
{"databaseType":"PostgreSQL","sql":"CREATE TABLE User (\n  id SERIAL PRIMARY KEY,\n  email VARCHAR(255) UNIQUE NOT NULL,\n  name VARCHAR(100),\n  isActive BOOLEAN DEFAULT true\n);"}
Output
{
  "databaseType": "PostgreSQL",
  "sql": "CREATE TABLE User (\n  id SERIAL PRIMARY KEY,\n  email VARCHAR(255) UNIQUE NOT NULL,\n  name VARCHAR(100),\n  isActive BOOLEAN DEFAULT true\n);"
}

Posts & Authors

Runtime-verified example for sql-to-prisma-schema
Input
{"databaseType":"PostgreSQL","sql":"CREATE TABLE Author (\n  id INT PRIMARY KEY,\n  name VARCHAR(255)\n);\n\nCREATE TABLE Post (\n  id INT PRIMARY KEY,\n  title VARCHAR(255) NOT NULL,\n  authorId INT,\n  FOREIGN KEY (authorId) REFERENCES Author(id)\n);"}
Output
{
  "databaseType": "PostgreSQL",
  "sql": "CREATE TABLE Author (\n  id INT PRIMARY KEY,\n  name VARCHAR(255)\n);\n\nCREATE TABLE Post (\n  id INT PRIMARY KEY,\n  title VARCHAR(255) NOT NULL,\n  authorId INT,\n  FOREIGN KEY (authorId) REFERENCES Author(id)\n);"
}

Use Cases

  • Migrating an existing SQL database design to a new Prisma-based application without connecting to a live database.
  • Prototyping data models and visualizing how traditional SQL schemas map to Prisma's ORM syntax.
  • Generating Prisma models offline from database dumps or exported DDL scripts.
  • Learning Prisma schema syntax by comparing it side-by-side with familiar SQL definitions.

Frequently Asked Questions