# Database Table Destination

The *Database Table Destination* object in Astera provides the functionality to write data to a database table. This destination option provides a great deal of control over how data is written to a database table with its extended data loading options.

Astera Data Stack supports a wide range of on-premise and cloud-based databases including SQL Server, Oracle, DB2, Sybase, MySQL, Salesforce, Microsoft Dynamics CRM, and more.

Astera delivers highly optimized implementations for these database connectors including high-performance bulk inserts, set-based updates, and transaction management. This, combined with Astera's parallel-processing architecture, delivers industrial-strength performance and scalability.

## **Configuring the Database Table Destination Object**

1. To add a *Database Table Destination* object to your dataflow, go to *Toolbox > Destinations > Database Table Destination*. If you are unable to see the Toolbox, go to *View > Toolbox* or press Ctrl + Alt + X.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FiGzg0w2RhiV6XTOzMmTh%2Fimage.png?alt=media&#x26;token=88354ece-48fa-47c1-bc78-f76fdae7f49e" alt=""><figcaption></figcaption></figure>

2. Drag and drop the *Database Table Destination* object onto the designer.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FDLHeh4tf4xBkx5WVwqM1%2FDatabase%20Table%20Destination%20Gif%201.gif?alt=media&#x26;token=e4209b00-ad23-4ade-8e3d-37c2c5ac58ac" alt=""><figcaption></figcaption></figure>

If you look at it, the *Database Table Destination* object is empty right now, as in, it does not have any fields or mappings. This is because the object has not been configured yet. There are two empty sub-nodes for *Input* and *Output* under the *DatabaseDest* root node.

## **Connecting to the Database**

1. To configure the properties of the *Database Table Destination* object, right-click on the header and select *Properties* from the context menu.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FodXnq12YUeRBgLnCh454%2Fimage.png?alt=media&#x26;token=5c8fea7a-a92c-4a04-91ed-ef317499719f" alt=""><figcaption></figcaption></figure>

This will open a new window, *Database Connection,* in Astera.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2Fy79lk8uhBavSTZhKDNtx%2Fimage.png?alt=media&#x26;token=b43bb0d1-7a44-43b9-bf50-f933b7267660" alt=""><figcaption></figcaption></figure>

* First, you will need to select the relevant data provider from the *Data Provider* drop-down list.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FKveKhSn8LvwINtfUTZzY%2Fimage.png?alt=media&#x26;token=b21b200a-98fc-499d-b478-ca29046771a6" alt=""><figcaption></figcaption></figure>

This is where you select the specific database provider you want to connect to. For instance, if you want to write your data to a SQL database, select *SQL Server* from the list. The connection details will vary according to the data provider selected.

* *Test Connection* to make sure that your database connection is successful and click *Next*.

2. Now, you need to provide details to configure a connection with the destination database.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FRoPTWalZU19gywFZwwCV%2Fimage.png?alt=media&#x26;token=7b0bf634-a39e-4a49-a587-5adbfb96410a" alt=""><figcaption></figcaption></figure>

* Enter your *User ID* and *Password.* You can also use the *Recently Used* drop-down list to connect to a recently-connected database.

## **Picking Table**

The next window is the *Pick Table* window. Here, you can choose from the following options:

* *Pick Table:* To append data into an existing table.
* *Create/Replace*: To write data to a new table or replace an existing table.
* *Truncate Table*: To overwrite data in an existing table.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FlcGrRRPs93gTkrVdxVRz%2Fimage.png?alt=media&#x26;token=5221c2c7-4df8-4ea6-bf7e-70b8611ec129" alt=""><figcaption></figcaption></figure>

* Choose the option based on your requirements. In this case, we will select the *Create/Replace Table* option and create a new table in the database.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FfqoNoquZgaE3q7PzrGLD%2Fimage.png?alt=media&#x26;token=f35d4298-f686-45c2-88eb-85c92dd49191" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note:** We will be creating a new table *CustomerDetails*.
{% endhint %}

## **Mapping**

For a database destination object to work, data fields should be mapped to the object so that the mapped data can be written to the destination.

* Configure the source object and place it onto the designer next to the *Database Table Destination* object.

{% hint style="info" %}
**Note:** In this case, a *Customers* sample data coming in from an *Excel Workbook Source*, will be written to a *Database Table Destination*.
{% endhint %}

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F6W3GtxSoRBx2RDvogKqy%2Fimage.png?alt=media&#x26;token=1321fe5d-3ffa-4036-91ea-20c93ff3d1a6" alt=""><figcaption></figcaption></figure>

* Map the source object to the destination object. Data mapping from the source to the destination can be done in the following ways:

i. Dragging and dropping the parent node from the source object onto the destination object.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FkAYEofF34Lgmo1XvMxG4%2FDatabase%20Table%20Destination%20Gif%202.gif?alt=media&#x26;token=b88711a6-1a60-480b-b394-12174815a9af" alt=""><figcaption></figcaption></figure>

ii. Mapping the output port of the source object onto the input port of the destination object.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FMcTx5kmaRhdUzZuN4Xpq%2FDatabase%20Table%20Destination%20Gif%203.gif?alt=media&#x26;token=eb17eb31-6fe1-445b-955c-ae491329ba0a" alt=""><figcaption></figcaption></figure>

iii. Right-clicking on the parent node inside the source object and selecting *Write to > Database Table Destination* from the context menu.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FE5Sov8YEIhSYPZPAxvlC%2FDatabase%20Table%20Destination%20Gif%204.gif?alt=media&#x26;token=7fcbda18-9fc7-4a4f-8dba-c1419e229fd5" alt=""><figcaption></figcaption></figure>

* The fields are now mapped.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F0U5bPblcMmNt7hW3fEfD%2Fimage.png?alt=media&#x26;token=109f5c06-2aa4-41a8-92f0-c64b1a557d0c" alt=""><figcaption></figcaption></figure>

## **Configuration**

1. The *Pick Table* window has some other configuration options.

* *Define Input Ports for Mapping*
  * *Single Port*: Works only for the records that have been updated and won’t treat records individually.
  * *Individual Ports for Actions*: Works for all the records individually as per the selected action. The actions that are provided are: *Insert*, *Delete*, *Update,* and *Upsert*.
* *Database Options*
  * *Use constraint-based write*: When the layout has certain restrictions that you want to keep while writing.
  * *Preserve system-generated key values*: To generate unique values for the selected primary key in the dataset. This option is only available if you assign at least one field in your destination layout as the System Generated field.
  * *Use transaction*
    * *Always commit the transaction on completion*: When you want the whole transaction to be processed regardless of errors.
    * *Rollback if there are any errors*: When you don’t want the dataset to process in case of errors and roll back completely.
  * *Check field lengths* for the incoming dataset with the lengths defined in the destination layout.
  * *Check for null values* from the incoming dataset.
  * *Write null strings as zero-length strings* where the string values are null, their length will be defined as zero.
  * *Write null numeric values as zeros* for the numeric data types, the null values will be defined as zeros.
  * *Disable indexes during load* for lengthy processing.
* *Data Load Options*
  * *Bulk insert with batch size* when you want the whole dataset to be loaded in batches for the specified size. Typically, larger batch sizes result in better transfer speeds; however, performance gains may be less with relatively large batch sizes.
  * *Bulk insert with all records in one batch* when you want all the records to be loaded into a table in one batch. In this case, any database-specific error in your transfer won’t show until the end of the transfer.
  * *Use single record insert* when you want records to be loaded individually. Records are inserted into a destination table one by one. This loading option renders the slowest performance among the three insert types. However, any errors or warnings during the transfer are displayed immediately as the transfer progresses.
* *Parallel Writing* is used when you want to expedite the data loading process by increasing the number of writers for that dataset.

2. Once you have specified your options on this screen, click *Next*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FpSFc8NrPEb0eIgdE3CaN%2Fimage.png?alt=media&#x26;token=256ada95-05ce-4213-8828-1573cb1210f0" alt=""><figcaption></figcaption></figure>

3. The next window you will see is the *Layout Builder*. Here, the layout of the database destination file can be modified.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F9R00phsIN1ODWWEIgPOh%2Fimage.png?alt=media&#x26;token=2bac25e5-5810-4406-a345-862bec2bdf7d" alt=""><figcaption></figcaption></figure>

* To add a new field to the layout, go to the last row of the layout (Name column), which will be blank and double-click on it, and a blinking text cursor will appear. Type in the name of the field to be added, and select the properties for it. A new field will be added to the destination table’s layout.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FEIXevCMoZn9AsI1hUwhM%2Fimage.png?alt=media&#x26;token=d16ddc7a-d91f-4a2d-8e47-77fab113ef33" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note**: In this example, we will add a new field *AccountType* to the layout.
{% endhint %}

* To delete a field from the layout, click on the serial column of the row that is to be deleted. The selected row will be highlighted in blue.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FOmeI5cxDnnn58jF1cYm3%2Fimage.png?alt=media&#x26;token=2963b022-36ec-4eef-ac67-8d552960e4ba" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note**: Here, we are deleting the *Fax* field from the layout.
{% endhint %}

* Right-click on the highlighted line and a context menu will appear which will have the option to *Delete*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FC9qJryms0GXufku7CP5h%2Fimage.png?alt=media&#x26;token=8d71fbc1-29ac-4054-b0a0-38b77b741488" alt=""><figcaption></figcaption></figure>

Selecting *Delete* will delete the entire row.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2Fgua7CyXjXsq31N1MMZGB%2Fimage.png?alt=media&#x26;token=1542e68e-15e3-4438-8854-976bf519220e" alt=""><figcaption></figcaption></figure>

The field is now deleted from the layout and won’t appear in the output.

* To change the position of any field and move it below or above another field in the layout, select the row and use the Move up/Move down buttons.

{% hint style="info" %}
**Note**: Find the Move up/Move down icons on the top left of the builder.
{% endhint %}

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FSpLRfOyIu2WhKt8Jrhiw%2Fimage.png?alt=media&#x26;token=a8b0b3af-0a56-49e6-bd9a-1fcfa62a086f" alt=""><figcaption></figcaption></figure>

For example: To move the *Country* field right below the *Region* field, select the row and click the Move up button in the toolbar at the top, to move the field up from the 9th to the 8th position.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F4zwv8Gm2GbsQjZhXsOwR%2Fimage.png?alt=media&#x26;token=25e62ba7-01a8-4ebd-9c48-001981e5bd2c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FOZWXxLhDaY608gsrNeYQ%2Fimage.png?alt=media&#x26;token=3d2181ee-2539-4e4f-b694-004f6971d37c" alt=""><figcaption></figcaption></figure>

4. Once the object layout is configured, click *Next*. A new window will appear, *Config Parameters*, which allows us to further configure and define the parameters for the database destination file.

Parameters can provide easier deployment of flows by eliminating hardcoded values and provide an easier way of changing multiple configurations with a simple value change during the runtime.

{% hint style="info" %}
**Note**: Parameters left blank will use their default values assigned on the properties page.
{% endhint %}

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FjnkhT8h7rsWd8L5NlZaF%2Fimage.png?alt=media&#x26;token=c1423c10-e7d8-4709-9d09-b44779389e91" alt=""><figcaption></figcaption></figure>

5. Click *Next*. A *General Options* window will appear. Here you have the following options:
   * *Comments* can be added.
   * *General Options* are given, which relate to the processing of records in the destination file:
     * *Clear Incoming Record Messages:* For any messages coming in from objects preceding the current object to be cleared.
     * *Do Not Process Records With Errors:* Will not let erroneous records to proceed further for the output.
     * *Do Not Overwrite Default Values with Nulls:* Ensure that values are not overwritten with null values in the output.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FnXMpGbyd1lBt1vQoqupG%2Fimage.png?alt=media&#x26;token=fd001481-35d8-4420-b464-f6d778588edb" alt=""><figcaption></figcaption></figure>

6. Click *OK*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FXU2FmiwEXz1bhnVsOw3w%2Fimage.png?alt=media&#x26;token=afc64731-6860-4ae6-8a46-1f06bd403306" alt=""><figcaption></figcaption></figure>

The *DatabaseDest* object is now configured according to the settings made in the properties window.

{% hint style="info" %}
**Note**: The changes that were made in this case are:

* Added a new field *AccountType* in the layout and mapped its value from the [*Constant Value Transformation*](https://documentation.astera.com/v/astera-data-stack-v8/dataflows/transformations/constant-value-transformation) object.
* Moved the *Country* field below the field *Region* field.
  {% endhint %}

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FMtpXvlcJjvTfr7sgYAoi%2Fimage.png?alt=media&#x26;token=824fbd6b-032b-4eeb-a725-03fe165ff7b0" alt=""><figcaption></figcaption></figure>

The *Database Table Destination* object is now successfully configured, and the destination file can now be created by running the dataflow.

* The job can be traced through the *Job Progress* window once the job starts running.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FcoLsgi3LBaVhibNZiOXC%2Fimage.png?alt=media&#x26;token=5010309c-aa4c-4f9f-aa2c-9a369f7e4dc2" alt=""><figcaption></figcaption></figure>
