Generate SQL CREATE statement using API

Hi, is there a way to generate the SQL CREATE statement when generating data? I noticed that it is possible using the UI but I can’t find any reference to it in the API.

Assuming you mean the Mockaroo data API, and not the mock API, this seems to be what you want: POST /api/generate(.format). In the Formats section, there is a table showing how to specify the type of output - 2nd from the bottom is sql.

If that’s not what you mean, please add additional detail.


While using the UI to generate data, it is possible to check the field highlighted in the first image; when this field is checked the generated data file will also include a SQL CREATE TABLE statement that creates a table that can contain the generated data.
What I want to know is if it is possible to use this feature using API calls and not the UI.

Yes and Maybe

If you define a schema in the UI, you can call it using the API, so “Yes”. For example,

Schema: Mockaroo - Random Data Generator and API Mocking Tool | JSON / CSV / SQL / Excel. The checkbox is checked.

Using the following API Call: GET https://api.mockaroo.com/api/a1f81700?count=50&key=35bcad40 I got this:

create table MOCK_DATA (
id INT,
first_name VARCHAR(50)
);
insert into MOCK_DATA (id, first_name) values (1, ‘Pattin’);
insert into MOCK_DATA (id, first_name) values (2, ‘Julie’);

Just clicking on the API URL above will generate a mock data file with the create table stmt at the top.

If you mean dynamically creating a schema using the API and passing in the format in the URL or dynamically creating this in the Mock API, “Maybe”. The format has a type called “SQL Expression” which proports to be verbatim SQL, so perhaps you could create the table creation yourself and put it in the front of the data stream. I don’t have any experience with the dynamic generation, you will need to experiment, sorry.

HTH.