SQL to Prisma Schema Generator
Generate Prisma schema models directly from your SQL DDL. This tool parses CREATE TABLE statements and produces Prisma models with correct types, decorators, and field mappings.
SQL to TypeScript / Prisma / Drizzle Converter
Convert SQL CREATE TABLE statements into TypeScript interfaces, Prisma schema, or Drizzle ORM table definitions. Supports PostgreSQL, MySQL, and SQLite syntax.
SQL Type Mapping Reference
| SQL Type | TypeScript | Prisma |
|---|---|---|
| INT / INTEGER / SERIAL | number | Int |
| BIGINT / BIGSERIAL | number | BigInt |
| VARCHAR / TEXT / CHAR | string | String |
| BOOLEAN / BOOL | boolean | Boolean |
| TIMESTAMP / DATETIME | Date | DateTime |
| DECIMAL / NUMERIC | number | Decimal |
| JSON / JSONB | Record<string, unknown> | Json |
| UUID | string | String |
| BYTEA / BLOB | Buffer | Bytes |
How It Works
- SQL Parser -- parses CREATE TABLE statements supporting PostgreSQL, MySQL, and SQLite syntax including quoted identifiers, multi-word types, and constraints.
- TypeScript -- generates typed interfaces with SQL type mapping, nullable fields as
| nullor optional?. - Prisma -- generates Prisma models with @id, @default, @unique, @map, and @db.* annotations.
- Drizzle ORM -- generates table definitions using pgTable/mysqlTable/sqliteTable with correct column types and modifiers.
- Foreign keys -- detected from both inline REFERENCES and table-level FOREIGN KEY constraints.
- Everything runs in your browser -- no data is sent over the network.
What is Prisma Schema?
Prisma schema is the central configuration file for Prisma ORM. It defines your data models, their fields, types, and relationships using a declarative syntax. Each model maps to a database table, and Prisma uses the schema to generate a type-safe query client for TypeScript and JavaScript applications.
How the converter maps SQL to Prisma
The converter maps SQL column types to Prisma scalar types: INT becomes Int, VARCHAR becomes String, BOOLEAN becomes Boolean, TIMESTAMP becomes DateTime, DECIMAL becomes Decimal, and JSON/JSONB becomes Json. Constraints like PRIMARY KEY map to @id, UNIQUE to @unique, DEFAULT to @default, and AUTO_INCREMENT to @default(autoincrement()). Column names are converted to camelCase with @map annotations preserving the original SQL name.
Prisma annotations generated
The tool generates @id for primary keys, @unique for unique constraints, @default(autoincrement()) for serial/auto-increment columns, @default(now()) for timestamp defaults, @default(uuid()) for UUID generation, @map for column name mapping, @db.* annotations for database-specific types (e.g., @db.VarChar(255), @db.Uuid, @db.Timestamptz), and @@index/@@unique for table-level indexes.
Frequently Asked Questions
Does this tool handle foreign key relationships?
The tool detects REFERENCES and FOREIGN KEY constraints and annotates columns accordingly. For full Prisma relation fields, you may need to add relation annotations manually since Prisma relations require both sides of the relationship to be defined.
Which SQL dialects are supported?
The parser handles PostgreSQL, MySQL, and SQLite CREATE TABLE syntax including quoted identifiers (backticks and double quotes), multi-word types like TIMESTAMP WITH TIME ZONE, and dialect-specific features like SERIAL, AUTO_INCREMENT, and AUTOINCREMENT.
Related Convert Tools
JSON to Zod Converter
Convert JSON or JSON Schema to Zod validation schemas with $ref resolution, allOf/oneOf/anyOf, enum, format constraints, and required/optional fields
GraphQL to TypeScript
Convert GraphQL SDL schemas to TypeScript interfaces, types, enums, unions, and operations
TypeScript to JavaScript
Convert TypeScript to JavaScript — strip types, interfaces, enums, generics, and access modifiers to get clean JS output
JSON to SQL Converter
Convert JSON arrays to SQL CREATE TABLE and INSERT statements for PostgreSQL, MySQL, and SQLite with automatic type inference