# Import and export

> Export a table, a selection or the whole database as SQL, CSV or JSON, and import a SQL script or a CSV file.

Source: https://www.opendb.tools/en/docs/import-export

## Export

### A table or a filtered view

In the Tables tab, the grid's **Export** button exports:

- the **current view**, with its filters, or the **whole table**;
- as **CSV** or **JSON**.

The export is written in batches of 1,000 rows: the size of the table does not affect the memory used.

### The whole database

From the **Import or export** menu of the Tables tab, or by asking the agent:

```text
Export the orders and order_items tables as SQL.
```

| Format | Content |
|---|---|
| SQL | The `CREATE TABLE` and `INSERT` statements, in your engine's dialect |
| CSV | One CSV file per table, along with a `schema.sql` |

Tables are exported in the order of their foreign keys, so that the file can be imported back without errors.

### A selection of rows

The agent can export the result of a query rather than whole tables:

```text
Export the last 40 orders as CSV.
```

From the SQL editor, **Export** saves every row of the result shown.

### Compression

| Compression | Result |
|---|---|
| Zip | A `.zip` archive |
| Tar | A `.tar` archive |
| Gzip | A `.gz` file |
| None | The files as they are |

Without compression, several files are still grouped into a zip archive.

The default format and compression are set in **Settings → Exports**. An instruction saved in the [project memory](/en/docs/memory) or given in your request takes precedence.

### Where exports go

Into the `exports/` folder of your workspace:

```text
{project folder}/.opendb/users/{user}/exports/
```

This folder contains a `.gitignore`: your exports never end up in the project's Git repository.

Exporting requires the `EXPORT` privilege, on the project or on the tables involved.

## Import

Importing requires the `IMPORT` privilege.

### A SQL script

You can import a `.sql`, `.sql.gz` or `.zip` file, or paste the script directly.

Three execution modes:

| Mode | Behaviour |
|---|---|
| All or nothing | One error rolls back the whole import |
| Stop at the first error | What comes before the error stays applied |
| Continue despite the errors | Failing statements are skipped and reported, 50 at most |

OpenDB splits the script the way your engine's client would. A semicolon inside a text value, a comment or the body of a trigger does not end the statement, and MySQL's `DELIMITER` lines are honoured.

Transaction statements found in the script are ignored: the import handles its own.

### A CSV file into a table

In the Tables tab, open the table and then **Table actions → Import**.

1. Choose the file and the separator.
2. Say whether the first row holds the headers.
3. **Map** each column of the file to a column of the table. A preview shows the result.
4. Choose whether an empty value becomes `NULL`, and whether the table should be emptied before the import.

A CSV import is all or nothing: one invalid row cancels the lot.

## File size

Files sent from the browser are limited to 15 MB. For a larger file, import it in batches or use your engine's client.
