---
title: "Import and export"
description: "Import a SurrealQL script into a database with .Import() and export a database as a SurrealQL script with .Export() in the .NET SDK."
canonical_url: "https://surrealdb.com/docs/reference/dotnet/concepts/import-and-export"
sdk: ".NET SDK"
sdk_version: "1.0.1"
surrealdb_version: "4.x"
last_modified: "2026-11-24T05:29:47Z"
---

> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Import and export

Import a SurrealQL script into a database with .Import() and export a database as a SurrealQL script with .Export() in the .NET SDK.

The .NET SDK can load a SurrealQL script into the database it is connected to, and can write the database out as a SurrealQL script.

| Method | Description |
| --- | --- |
| [`db.Import()`](#import) | Imports data into a SurrealDB database |
| [`db.Export()`](#export) | Exports the database as a SurrealQL script |

## `.Import()` {#import}

Imports data into a SurrealDB database. To use this method, you need to be connected to a SurrealDB instance that is version `>= 2.0.0`.

```csharp title="Method Syntax"
await db.Import(string)
```

### Arguments

<table>
    <thead>
        <tr>
            <th colspan="2" scope="col">Arguments</th>
            <th colspan="2" scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>input</code>
                <label label="required" />
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The SurrealQL script used to import data in the database.
            </td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>cancellationToken</code>
                <label label="optional" />
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The cancellationToken enables graceful cancellation of asynchronous operations.
            </td>
        </tr>
    </tbody>
</table>

### Example usage

```csharp
string input = 
        """
        DEFINE TABLE foo SCHEMALESS;
        DEFINE TABLE bar SCHEMALESS;
        CREATE foo:1 CONTENT { hello: "world" };
        CREATE bar:1 CONTENT { hello: "world" };
        DEFINE FUNCTION fn::foo() -> string {
            RETURN "bar";
        };
        """;

await db.Import(input);
```

<br />

## `.Export()` {#export}

Export the database as a SurrealQL script. To use this method, you need to be connected to a SurrealDB instance that is version `>= 2.1.0`.

```csharp title="Method Syntax"
await db.Export(options)
```

### Arguments

<table>
    <thead>
        <tr>
            <th colspan="2" scope="col">Arguments</th>
            <th colspan="2" scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>options</code>
                <label label="optional" />
            </td>
            <td colspan="2" scope="row" data-label="Description">
                Export configuration options.
            </td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>cancellationToken</code>
                <label label="optional" />
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The cancellationToken enables graceful cancellation of asynchronous operations.
            </td>
        </tr>
    </tbody>
</table>

### Example usage

```csharp title="Only exporting db functions in a schema variable"
var options = new ExportOptions
{
    Users = false,
    Accesses = false,
    Params = false,
    Functions = true,
    Users = false,
    Versions = false,
    Tables = false,
    Records = false,
};

string schema = await db.Export(options);
```
