SQL → Code Generator
Paste a CREATE TABLE statement and generate the matching model class for your language. All processing happens in your browser.
About the SQL to Code Generator
When an application talks to an existing database, someone has to write the classes that mirror its tables — and keep the property names, types and nullability in sync with the columns. Doing it by hand for a 40-column table is slow and error-prone.
The SQL → Code Generator reads a CREATE TABLE statement and produces a matching model in the language you work in: a plain C# class (POCO), a C# Entity Framework entity with data annotations, a Python dataclass, a SQLAlchemy model or a TypeScript interface. SQL types are mapped to the closest native types and nullable columns become nullable properties. Everything runs in your browser.
Common uses
- Creating DTOs or entities for a legacy database without running a full scaffolding tool.
- Writing a TypeScript interface for an API whose data comes straight from a SQL table.
- Prototyping a Python script or FastAPI service on top of an existing schema.
- Keeping models in sync after a column is added or changed.
How to use it
- Paste a
CREATE TABLEstatement into the input box (or click Try Me). - Choose the target: C# POCO, C# EF Entity, Python Dataclass, Python SQLAlchemy or TypeScript.
- Press Generate and copy the code into your project.
Example
A table converted to a C# class:
CREATE TABLE Customers (
Id INT IDENTITY(1,1) PRIMARY KEY,
Email NVARCHAR(255) NOT NULL,
BirthDate DATE NULL,
Balance DECIMAL(18,2) NOT NULL
);
public class Customers
{
public int Id { get; set; }
public string Email { get; set; }
public DateTime? BirthDate { get; set; }
public decimal Balance { get; set; }
}
Tips and common pitfalls
- Use
decimal(C#) orDecimal(Python) for money;floatanddoublecannot represent amounts like 0.10 exactly. - Table names are usually plural and class names singular — rename
CustomerstoCustomerafter generating if that is your convention. - For whole databases, prefer your framework's scaffolding tool (
dotnet ef dbcontext scaffold,sqlacodegen) and use this generator for quick, single-table jobs. - Add
[MaxLength]or[StringLength]to string properties that map toNVARCHAR(n)columns, so your application can validate input before it reaches the database.
Frequently asked questions
Is my SQL sent to a server?
No. Parsing and code generation happen entirely in your browser.
Can I paste several tables at once?
The generator is built for one CREATE TABLE statement at a time. Generate each table separately for the cleanest results.
How are nullable columns handled?
Columns declared NULL (or without NOT NULL) become nullable types — for example int? in C#, Optional[int] in Python and an optional property in TypeScript.
What is the difference between the POCO and EF Entity options?
The POCO is a plain class with properties only. The EF Entity adds data annotations — [Table], [Key] for the primary key, [DatabaseGenerated] for identity columns and [Required] for non-nullable strings — plus a DbSet snippet for your DbContext.