- Select your source database dialect (e.g., PostgreSQL, MySQL) from the dropdown menu.
- Paste your raw SQL DDL statements (like CREATE TABLE) into the input area.
- Click the conversion button to process the SQL.
- Copy the generated Prisma models from the output area.
- Paste the models directly into your schema.prisma file.
SQL to Prisma Schema
SQL to Prisma Schema tool on AzWebTools.
Result
Fill inputs and click run.
How to Use This Tool
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, orENUM) translate into Prisma's scalar types (String,DateTime, orenum).
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,SERIAL→IntVARCHAR,TEXT→StringBOOLEAN→BooleanTIMESTAMP,DATETIME→DateTimeDECIMAL,NUMERIC→Decimal
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
- Language
- Prisma Schema Language (PSL)
- Primary Ecosystem
- Node.js, TypeScript
- File Extension
- .prisma
Examples
Basic User Table
{"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);"}{
"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
{"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);"}{
"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.