> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with Insert

> How to insert large numbers of records in bulk.

Used when there is a need to insert multiple records in a table, Insert requires a target table name, an array of target column names and a matching dataset. The dataset must be a two-dimensional array of string values, where the first dimension represents the data rows and the second dimension represents each data cell in the row.

## Data rows and column values

**Built-in table:**

| *Columns*: | contact\_id | name       | country\_id | business\_idx | category\_idx |
| ---------- | ----------- | ---------- | ----------- | ------------- | ------------- |
| **Row**    | "0"         | "Company1" | "220"       | "\[I:6]"      | "\[I:3]"      |
| **Row**    | "0"         | "Company2" | "98"        | "\[I:1]"      | "\[I:2]"      |
| **Row**    | "0"         | "Company3" | "27"        | "\[I:4]"      | "\[I:1]"      |

**Extra table:**

| *Columns*: | x\_name       | x\_description | x\_height  | x\_width     |
| ---------- | ------------- | -------------- | ---------- | ------------ |
| **Row**    | "cat"         | "in a hat"     | "\[I:123]" | "\[F:321.4]" |
| **Row**    | "Foozle"      | "Not woozels"  | "\[I:69]"  | "\[F:123.5]" |
| **Row**    | "Screwdriver" | "Philips head" | "\[I:54]"  | "\[F:345.3]" |

`Built-in tables` do not have to specify a primary key column. When not specified, all rows are automatically assigned primary key value from the sequence table. When present and equal to "0" or \[I:0] they are assigned from the sequence table. When primary key column values are greater than 0, they are used as-is, however, the operation aborts if there is a collision.

<Warning>
  Extra tables **must not** specify a primary key column.
</Warning>

## Insert Example

<Tabs>
  <Tab title="Agent RESTful API">
    ### Insert example

    ```csharp theme={null}
    using SuperOffice.WebApi;
    using SuperOffice.WebApi.Data;
    using SuperOffice.WebApi.Agents;

    // set up the DatabaseTable agent

    WebApiOptions options = //Get WebApiOptions with SystemUser Authorization
    DatabaseTableAgent dta = new DatabaseTableAgent(options);

    // table name

    string tableName = "y_rental";

    // table columns (non-nullable columns)

    var columns = new[] { "x_start", "x_end", "x_amount", "x_contact", "x_equipment" };

    // table row data

    var data = new string[][]
    {
      new[] {yesterday, today, CultureDataFormatter.EncodeInt(2), "123", "0" },
      new[] {yesterday, today, CultureDataFormatter.EncodeInt(200), "456", "1" },
    };

    MassOperationResult results = await dta.InsertAsync(tableName, columns, data);
    ```
  </Tab>

  <Tab title="Core API">
    ### Insert example

    ```csharp theme={null}
    using SuperOffice.Data.Dialect;
    using SuperOffice.CRM.Globalization;

    var mo = MassOperations.GetCurrent();

    // table name

    string tableName = "y_rental";

    // table columns (non-nullable columns)

    var columns = new[] { "x_start", "x_end", "x_amount", "x_contact", "x_equipment" };

    // use CultureDataFormatter to encode date and numerical values.

    var today = CultureDataFormatter.EncodeDateTime(DateTime.Today.DropFractionsOfSecond());
    var yesterday = CultureDataFormatter.EncodeDateTime(DateTime.Today.AddDays(-1).DropFractionsOfSecond());

    // table row data

    var data = new string[][]
    {
      new[] {yesterday, today, CultureDataFormatter.EncodeInt(2), "123", "0" },
      new[] {yesterday, today, CultureDataFormatter.EncodeInt(200), "456", "1" },
    };

    MassResult massResult = mo.Insert(tableName, columns, data);
    ```
  </Tab>
</Tabs>

The example inserts 2 rows into the `y_rental` table. Other unspecified columns in the table will be set to default values. As is with all extra tables, the primary key `y_rental.id`  will be auto-incremented by the database.


## Related topics

- [Working with Upsert](/en/api/bulk-operations/mass-operations/upsert.md)
- [Insert](/en/api/reference/restful/agent/databasetable_agent/insert.md)
- [Insert, update, and delete](/en/automation/crmscript/searchengine/se-insert-update-delete.md)
- [Respond to requests on your mobile device](/en/mobile/request/respond.md)
- [Insert Row](/en/api/reference/restful/rest/tablerecord/insert-row.md)
