SQL to Prisma Schema

Convert SQL CREATE TABLE statements to Prisma schema models with type mapping, relations, and indexes.

About This Tool

The SQL to Prisma Schema converter is a free browser-based tool that transforms SQL CREATE TABLE statements into Prisma schema definitions. Prisma is a modern, type-safe ORM for Node.js and TypeScript that uses a declarative schema file to define your database models. Instead of manually translating your existing SQL database structure into Prisma's schema format, this tool automates the process and generates clean, idiomatic Prisma models in seconds.

The converter parses your SQL and maps column types to their Prisma equivalents. Standard SQL types like VARCHAR, INTEGER, BOOLEAN, TIMESTAMP, and JSON are all handled automatically. It also recognizes database-specific types such as PostgreSQL's SERIAL, BYTEA, and JSONB, as well as MySQL's AUTO_INCREMENT and TINYINT(1) boolean pattern. Table names are converted to PascalCase model names and column names to camelCase field names, with @map and @@map attributes preserving the original database identifiers.

Relations are inferred from FOREIGN KEY constraints and inline REFERENCES clauses. The tool generates proper Prisma @relation attributes with the correct fields and references arguments. Composite primary keys become @@id, composite unique constraints become @@unique, and CREATE INDEX statements are converted to @@index annotations on the model.

All processing happens entirely in your browser. Your SQL statements never leave your machine — there are no server round-trips, no logging, and no third-party services involved. This makes it safe to use with production database schemas and sensitive table definitions. The tool is ideal for migrating existing databases to Prisma, prototyping data models, or simply learning how SQL structures translate to Prisma's schema language.

How to Use

  1. Paste one or more SQL CREATE TABLE statements into the SQL Input panel on the left.
  2. The Prisma schema output updates automatically in the right panel as you type.
  3. Select your Database provider (PostgreSQL, MySQL, SQLite, or SQL Server) to ensure correct type mapping.
  4. Toggle @updatedAt to automatically add the Prisma @updatedAt attribute to columns named updated_at.
  5. Toggle @default(now()) to add @default(now()) to columns named created_at.
  6. Toggle datasource to include the datasource and generator blocks at the top of the output.
  7. Click Copy or press Ctrl+Shift+C to copy the generated Prisma schema to your clipboard. Use Sample to load example SQL.

Popular SQL to Prisma Examples

View all SQL to Prisma examples →

FAQ

Which SQL dialects are supported?

The parser supports standard SQL CREATE TABLE syntax and handles dialect-specific features from PostgreSQL, MySQL, SQLite, and SQL Server. This includes SERIAL / BIGSERIAL (PostgreSQL), AUTO_INCREMENT (MySQL), AUTOINCREMENT (SQLite), and IDENTITY (SQL Server). Select the correct database provider in the options to get the most accurate type mapping.

How are SQL types mapped to Prisma types?

Common mappings include: INT / INTEGER to Int, BIGINT to BigInt, VARCHAR / TEXT to String, BOOLEAN to Boolean, DECIMAL / NUMERIC to Decimal, TIMESTAMP / DATETIME to DateTime, JSON / JSONB to Json, BLOB / BYTEA to Bytes, and UUID to String @db.Uuid.

How are foreign keys converted to Prisma relations?

Both inline REFERENCES clauses and table-level FOREIGN KEY ... REFERENCES constraints are detected. The tool generates a scalar field for the foreign key column and a relation field with the @relation(fields: [...], references: [...]) attribute pointing to the referenced model and field.

Does it handle composite primary keys?

Yes. When the SQL defines a composite primary key via PRIMARY KEY (col1, col2), the tool generates a @@id([field1, field2]) attribute on the Prisma model instead of individual @id annotations. All columns in the composite key are marked as required (non-nullable).

How are table and column names converted?

Table names are converted to PascalCase for Prisma model names (e.g., user_accounts becomes UserAccounts). Column names are converted to camelCase for field names (e.g., created_at becomes createdAt). When the converted name differs from the original, @map("original_name") or @@map("original_table") attributes are added to preserve the database mapping.

Is my data safe?

Yes. All parsing and code generation runs entirely in your browser using JavaScript. No data is sent to any server. You can verify this by checking the Network tab in your browser's developer tools while using the tool.

Can I convert multiple tables at once?

Yes. Paste multiple CREATE TABLE statements separated by semicolons and the tool will generate a Prisma model for each table. You can also include CREATE INDEX statements, which will be converted to @@index or @@unique attributes on the corresponding models.

Related Tools