SQL CREATE TABLE Generator · Tutorial
How to design a database table from API JSON
6 min readintermediateUpdated
You want to store records from an API in your own database. You will paste a sample response, let the tool infer the columns, and adjust keys and types for the database you use.
What you need
- The SQL CREATE TABLE Generator
- A sample JSON response with several records
Steps
Paste the array of records
Load the example list of customers. If your API wraps records, such as
{"data": [...]}, paste only the array inside.Review the types
joinedcontains dates only, so it becomes DATE;last_loginhas times, so it becomes TIMESTAMPTZ in PostgreSQL.balancebecomesDECIMAL(10, 2)because money must be exact.Notice nullable columns
last_loginis empty for one customer, so it has no NOT NULL. Every other column is required.Switch database
Change Database to MySQL: timestamps become DATETIME and identifiers are quoted with backticks. Choose SQL Server and text becomes NVARCHAR.
Try it yourself
Opens the SQL CREATE TABLE Generator with this tutorial's sample loaded.
Common mistakes
- Storing money as floating point
- Keep Exact DECIMAL for decimals ticked. DOUBLE can turn 0.1 + 0.2 into 0.30000000000000004.
- Nested objects in one column
- Nested data becomes a JSON column. If you query inside it often, move it to its own table with a foreign key instead.
Next steps
Go back to the SQL CREATE TABLE Generator, or keep going with one of these: