✔How to export and import data using the export and import data wizards, SQL statements export into and import from, and the download option in the SQL console results tab
✔How to export and import schema objects using export and import catalog wizards and the SQL statements export and import
✔How to use cloud storage providers as a target when exporting or importing
An SAP HANA database such as SAP HANA Cloud free tier, or the SAP HANA, express edition that includes the SAP HANA database explorer
Data lake Files, Amazon AWS, Google Cloud, or Microsoft Azure accounts will be needed for optional steps in this tutorial.
You have completed the first 3 tutorials in this group.
Steps
Intro
The following steps will demonstrate a few ways to export and import data such as the contents of tables or views as well how to export and import database schema or catalog objects.
A few differences between exporting and importing data and importing and exporting catalog objects are:
Data export and import works with one table or view
Catalog export or import works with more than one object at one time
Catalog export or import can include additional objects such as functions and procedures
Catalog export or import includes the SQL to recreate the object
Step 1Export and import data
—
The following tables list the different options available in the SAP HANA database explorer to export and import data from a single table or view.
The following steps will attempt to demonstrate an export and import of data from the maintenance table using the download option from the SQL console and the import data wizard.
Enter the SQL statement below.
SQL
SELECT*FROMMAINTENANCE;
Left-click on the download toolbar item.
Download
Choose Download.
Download options
There is a setting that controls the number of results displayed which may need to be adjusted for tables with larger results.
Maximum rows to display setting
Enter the SQL statement below to delete the rows in the table. They will be added back in the next sub-step.
SQL
DELETEFROMMAINTENANCE;
Right-click on the maintenance table and choose Import Data.
Open Import Data Wizard
Browse to the previously downloaded CSV file and complete the wizard.
Choose file to import
The header row in the data.csv file is used to set the initial values of the source column to database column mappings.
Choose file to import
Complete the wizard.
import succeeded
After completing the wizard, the contents of the maintenance table should now be the same as it was before the previously executed delete statement.
With SAP HANA, express edition, the following statements can be executed to export and import from a directory on the SAP HANA file system assuming that the directory exists and the user hxeadm has permission to access it.
Step 2Use cloud storage services for export and import (optional)
+
The following steps are for illustrative purposes only and are not meant to be followed. Complete steps for working with cloud storage services are provided in steps 3, 4, 6, and 7.
With SAP HANA Cloud, an export data wizard is available.
Export Data Wizard
It can be used to export data to cloud storage providers such as SAP HANA Cloud, data lake Files, Amazon S3, Microsoft Azure, Google Cloud Storage, and Alibaba Cloud OSS.
available cloud storage providers
The screenshot below shows the data lake Files being used as an export target.
Export Data Wizard
Once the wizard has finished, the exported CSV file can be seen in the data lake Files container.
exported CSV
The wizard makes use of the export into statement. An example is shown below:
The import data wizard provides a corresponding option to import from cloud storage providers.
Export Data Wizard
The wizard makes use of the import from statement. An example is shown below:
SQL
--DELETE FROM MAINTENANCE;
IMPORTFROMPARQUETFILE'azure://danstestsa:sp=racwdl&st=2021-01-09T13:00:46Z&se=2021-01-10T13:00:46Z&sv=2019-12-12&sr=c&sig=TP%2BVYhcvSPDc4DZxcls6vN%2BCLHDNagedbei2IuEZsWU%3D@myblobcontainer/maintenance.parquet'INTOMAINTENANCEWITHFAILONINVALIDDATA;
Step 3Use data lake Files for export and import from an SAP HANA Cloud, SAP HANA database (optional)
+
The following steps walk through the process of exporting to and importing data using data lake Files with a SAP HANA Cloud, SAP HANA database. This step requires a productive SAP HANA Cloud data lake instance as data lake files is currently not included in the free tier service plan.
Add the certificate ID (ex: 123456) from the previous statement into <CERTIFICATE_ID>.
SQL
ALTERPSEHTTPSADDCERTIFICATE<CERTIFICATE_ID>;--ALTER PSE HTTPS DROP CERTIFICATE <CERTIFICATE_ID>;
Then, set the own certificate with the client private key, client certificate, and Root Certification Authority of the client certificate in plain text. Make sure you have completed steps 3 and 4 in the Getting Started with Data Lake Files HDLFSCLI tutorial to configure the trust setup of the data lake Files container.
SQL
ALTERPSEHTTPSSETOWNCERTIFICATE'<Contents from client.key>
<Contents from client.crt>
<Contents from ca.crt>';--GRANT REFERENCES ON PSE HTTPS TO USER1;
SELECT*FROMPSE_CERTIFICATES;
The above commands create a personal security environment (PSE), create a certificate, and add the certificate to the PSE.
Execute the following SQL to store a credential in the database for the user.
Step 4Use data lake Files for export and import from an SAP HANA Cloud, data lake Relational Engine database (optional)
+
The following steps walk through the process of exporting to and importing data using data lake Files with a SAP HANA Cloud, data lake Relational Engine database. This step requires a productive SAP HANA Cloud data lake instance as data lake files is currently not part of free tier. The following steps assume you have followed the first two sub steps in the previous step so that a data lake Files connection has been added to the SAP HANA database explorer.
Create a database credential for the data lake Files container. This step is required if you wish to export to a data lake Files instance that is not the one associated with the data lake Relational Engine. Open a SQL Console connected to a data lake Relational Engine instance and execute the below SQL statements.
SELECT*FROMSYSPSECERTIFICATE;ALTERPSEHTTPSSETOWNCERTIFICATE'<Contents from client.key>
<Contents from client.crt>
<Contents from ca.crt>';----ALTER PSE HTTPS UNSET OWN CERTIFICATE;
SQL
SELECT*FROMSYSCREDENTIAL;CREATECREDENTIALFORCOMPONENT'SAPHDLRELOADUNLOAD'PURPOSE'DL_FILES'TYPE'X509'PSEHTTPS;--DROP CREDENTIAL FOR COMPONENT 'SAPHDLRELOADUNLOAD' PURPOSE 'DL_FILES' TYPE 'X509';
Export or unload the data from the MAINTENANCE table to a data lake Files instance.
The below example targets the data lake Files instance that is attached to the data lake Relational Engine.
Step 5Use Google Cloud Storage (GCS) for data exports and imports (optional)
+
The following steps walk through the process of exporting to and importing data from Google Cloud Storage service with a SAP HANA Cloud, SAP HANA database.
Add the Owner role so that the service account can access the resources in the project.
create a service account
In the generated service account, add a key.
add a key to the service account
Once complete, a JSON file will be downloaded that contains the client_email and private_key which will be used when accessing the bucket.
Remove any line breaks (i.e. \n) from the private key. This can be done by pasting the private key into a new SQL console and opening the search and replace menu (Ctrl-F).
Remove line breaks
Create Credentials (Recommended)
You can view your service account email in the Service Accounts tab.
View Service Account
Execute the following SQL to store the private key and service account as a credential in the database. Paste the service account email and private key as user and password.
SQL
CREATECREDENTIALFORCOMPONENT'SAPHANAIMPORTEXPORT'PURPOSE'GoogleCloud'TYPE'PASSWORD'USING'user=<client_email>;password=<private_key>';SELECT*FROMCREDENTIALS;--DROP CREDENTIAL FOR COMPONENT 'SAPHANAIMPORTEXPORT' PURPOSE 'GoogleCloud' TYPE 'PASSWORD';
A Google Storage SSL certificate is required to connect to the Google Cloud Storage bucket via the SAP HANA Cloud, SAP HANA database. Open your SQL console within SAP HANA database explorer and run the following commands to create a certificate.
Add the certificate ID (ex: 123456) from the previous statement into <CERTIFICATE_ID>. Set the purpose to remote source.
SQL
ALTERPSEHTTPSADDCERTIFICATE<CERTIFICATE_ID>;--ALTER PSE HTTPS DROP CERTIFICATE <CERTIFICATE_ID>;
SETPSEHTTPSPURPOSEREMOTESOURCE;SELECT*FROMPSE_CERTIFICATES;
The above commands create a personal security environment (PSE), create a certificate, add the certificate to the PSE, and set the purpose to remote source.
The GTS Root R1 certificate used above was downloaded from Google Trust Services’ Repository under Download CA certificates > Root CAs >. It was downloaded in the .PEM format.
Run the following commands within the SQL console to perform an export using a Google Cloud Storage bucket.
There are two ways to use the export commands as shown below.
SQL
--Uses the previously stored credential
--EXPORT INTO PARQUET FILE 'gs://<bucket>/<objectKey>' FROM MAINTENANCE WITH CREDENTIAL 'GoogleCloud';
EXPORTINTOPARQUETFILE'gs://hc-storage-bucket/maintenance.parquet'FROMMAINTENANCEWITHCREDENTIAL'GoogleCloud';--Uses the private key as part of the SQL statement
--EXPORT INTO PARQUET FILE 'gs://<client_email>:<private_key>@<bucket>/<object_id>' FROM MAINTENANCE;
EXPORTINTOPARQUETFILE'gs://hc-service-account@hc-storage-proj.iam.gserviceaccount.com:-----BEGIN PRIVATE KEY-----MIIEv...-----END PRIVATE KEY-----@hc-storage-bucket/maintenance2.parquet'FROMMAINTENANCE;
An alternative to the above SQL commands is to use the Export Data Wizard. The Wizard can be accessed by right clicking a table or view and choosing Export Data. When using the export wizard, the “gs://” prefix is not needed when specifying the GCS Path.
Export Data Wizard
Verify the export was completed successfully by refreshing your bucket within Google Cloud Console.
Successful Export
Enter the SQL statement below to delete the rows in the table. They will be added back in the next sub-step when the import command is shown.
SQL
DELETEFROMMAINTENANCE;
Run the following commands within the SQL console to perform an import using a Google Cloud Storage bucket.
SQL
--Uses the previously stored credential
--IMPORT FROM PARQUET FILE 'gs://<bucket>/<objectKey>' WITH CREDENTIAL 'GoogleCloud';
IMPORTFROMPARQUETFILE'gs://hc-storage-bucket/maintenance.parquet'INTOMAINTENANCEWITHFAILONINVALIDDATACREDENTIAL'GoogleCloud';--Uses the private key as part of the SQL statement
--IMPORT FROM PARQUET FILE 'gs://<client_email>:<private_key>@<bucket>/<object_id>' INTO MAINTENANCE WITH FAIL ON INVALID DATA;
IMPORTFROMPARQUETFILE'gs://hc-service-account@hc-storage-proj.iam.gserviceaccount.com:-----BEGIN PRIVATE KEY-----MIIEvg...-----END PRIVATE KEY-----@hc-storage-bucket/maintenance2.parquet'INTOMAINTENANCEWITHFAILONINVALIDDATA;
** Max file size in archive is 8 GB (SAP Note 2907201).
Similar to the first section, the maintenance table will be exported and re-imported. The export statement and the associated export catalog wizard have additional options, including the ability to include other schema objects such as functions and procedures as well as the option to include the SQL statements to recreate the objects.
Right-click on the instance HC_HDB (USER1) and choose Export Catalog Objects.
Open Export Catalog Objects Wizard
Choose Local Computer for the export location and provide a name for the Local Archive. Click on Add Catalog Objects and search for the table Maintenance. Select an export format such as CSV and press Export.
Export Catalog Objects Wizard
Examine the available export format options.
Format Options
Binary Raw is the binary format for SAP HANA Cloud and Binary Data is the format option for SAP HANA as a Service and SAP HANA on-premise.
The archive file contains the SQL to recreate the table as well as the data of the table, as shown below.
Exported file
Enter the SQL statement below to drop the table. It will be added back in the next sub-step.
SQL
DROPTABLEMAINTENANCE;
Right-click on the instance HC_HDB (USER1) and choose Import Catalog.
Open Import Data Wizard
Browse to the previously downloaded .tar.gz file and complete the wizard. You can also rename the schema, if desired.
Choose file to import
The contents of the maintenance table should now be the same as it was before the previously executed drop statement.
SQL
SELECT*FROMMAINTENANCE;
Import succeeded
Step 7Use Azure cloud storage for exports and imports of catalog objects (optional)
+
The following steps walk through the process of using Microsoft Azure storage service as a target for an export catalog operation.
Create a resource group under the All services, General, Resource Manager.
Resource Group
Create a storage Service under All services, Storage, Storage accounts.
Storage Account
Create a blob container using the All services, Storage, Storage browser.
Blob Container
Generate an API key.
Generate API Key
Specify that the permissions and the expiry time.
Key Settings
Copy the generated query string and paste it into a text editor. This will be used in step 6.
Shared Access Signature
Create Credentials (Recommended)
Execute the following SQL to store the storage account and shared access signature (SAS) as a credential in the database. An example of <storage_account_name> is danstestsa.
SQL
CREATECREDENTIALFORCOMPONENT'SAPHANAIMPORTEXPORT'PURPOSE'Azure'TYPE'PASSWORD'USING'user=<storage_account_name>;password=<Blob_SAS_token>';SELECT*FROMCREDENTIALS;--DROP CREDENTIAL FOR COMPONENT 'SAPHANAIMPORTEXPORT' PURPOSE 'Azure' TYPE 'PASSWORD';
In the SAP HANA database explorer, add the certificate used by Microsoft to the HANA Cloud PSE. Open your SQL console within SAP HANA database explorer and run the following commands to create a certificate.
Add the certificate ID (ex: 123456) from the previous statement into <CERTIFICATE_ID>. Set the purpose to remote source.
SQL
ALTERPSEHTTPSADDCERTIFICATE<CERTIFICATE_ID>;--ALTER PSE HTTPS DROP CERTIFICATE <CERTIFICATE_ID>;
SETPSEHTTPSPURPOSEREMOTESOURCE;SELECT*FROMPSE_CERTIFICATES;
Provide a unique bucket name, choose your AWS region, and finish creating the bucket.
Bucket
Create a IAM User.
It is recommended that you create an IAM User instead of using the root account to manage the S3 bucket. If you already have an existing IAM User, then feel free to skip this step, and go ahead and generate an access key and secret key for an existing IAM User.
To create an IAM User, begin by logging in with your root credentials, and navigate to the Security Credentials tab.
Security Credentials Tab
Select add users.
New User
Specify user details such as User name and select the AWS credential type.
User Details
Select Attach existing policies directly and provide full Amazon S3 Access.
User Permissions
Finish creating the user.
Finish creating user
Copy and Save the Access key ID and Secret access key, as it will be required in step 5.
Access Key
Create Credentials (Recommended)
Execute the following SQL to store the access key and secret key as a credential in the database.
SQL
CREATECREDENTIALFORCOMPONENT'SAPHANAIMPORTEXPORT'PURPOSE'AWS'TYPE'PASSWORD'USING'user=<access_key>;password=<secret_key>';SELECT*FROMCREDENTIALS;--DROP CREDENTIAL FOR COMPONENT 'SAPHANAIMPORTEXPORT' PURPOSE 'AWS' TYPE 'PASSWORD';
Add the certificate ID (ex: 123456) from the previous statement into <CERTIFICATE_ID>. Set the purpose to remote source.
SQL
SELECT*FROMPSE_CERTIFICATES;ALTERPSEHTTPSADDCERTIFICATE<CERTIFICATE_ID>;--ALTER PSE HTTPS DROP CERTIFICATE <CERTIFICATE_ID>;
SETPSEHTTPSPURPOSEREMOTESOURCE;
Alternatively, you can use a Secret Key as a Credential (optional)
Secret Key
Pressing the Compose button shows the parsed AWS S3 path.
Compose
After the Export button is pressed, the results can be seen in the AWS S3 Console.
Export Result
The equivalent SQL statement is shown below:
SQL
--EXPORT MAINTENANCE AS PARQUET INTO 's3-<region>://<access_key>:<secret_key>@<bucket>/<object_id>' WITH REPLACE;
EXPORTMAINTENANCEASPARQUETINTO's3-us-east-1://AKIA3JHRPYB6KY3LSI76:dW9q+KxA0rgtaoBY3MnAAQIS96ypVEDvgxE8rIpt@maitrysawsbucket/maintenance'WITHREPLACE;
The previously stored credentials can be used for export using SQL:
SQL
--EXPORT MAINTENANCE AS PARQUET INTO 's3-<region>://<bucket>/<objectKey>' WITH CREDENTIAL 'AWS';
EXPORTMAINTENANCEASPARQUETINTO's3-us-east-1://maitrysawsbucket/maintenance'WITHCREDENTIAL'AWS';
An error regarding an invalid SSL certificate indicates an incorrect SSL certificate is being used. Additionally, if MFA (Multi-factor Authentication) is enabled, then the export may fail, so ensure that MFA is disabled before exporting.
Enter the SQL statement below to drop the table. It will be added back in the next step.
SQL
DROPTABLEMAINTENANCE;
Import the table using the import catalog objects wizard.
The AWS S3 Path (in the Import Catalog Objects Wizard) is of the format:
Select Load to load the catalog object in the wizard.
Import Catalog Wizard
The contents of the maintenance table should now be the same as it was before the previously executed drop statement.
The equivalent SQL statement is shown below:
SQL
--IMPORT MAINTENANCE AS PARQUET FROM 's3-<region>://<access_key>:<secret_key>@<bucket>/<object_id>' WITH REPLACE;
IMPORTMAINTENANCEASPARQUETFROM's3-us-east-1://AKIA3JHRPYB6KY3LSI76:dW9q+KxA0rgtaoBY3MnAAQIS96ypVEDvgxE8rIpt@maitrysawsbucket/maintenance'WITHREPLACE;
Alternatively, the previously stored credentials can be used for import:
SQL
--EXPORT MAINTENANCE AS PARQUET FROM 's3-<region>://<bucket>/<objectKey>' WITH CREDENTIAL 'AWS';
IMPORTMAINTENANCEASPARQUETFROM's3-us-east-1://maitrysawsbucket/maintenance'WITHCREDENTIAL'AWS';
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 9
1. Export and import data2. Use cloud storage services for export and import (optional)3. Use data lake Files for export and import from an SAP HANA Cloud, SAP HANA database (optional)4. Use data lake Files for export and import from an SAP HANA Cloud, data lake Relational Engine database (optional)5. Use Google Cloud Storage (GCS) for data exports and imports (optional)6. Export and import schema or catalog objects7. Use Azure cloud storage for exports and imports of catalog objects (optional)8. Use Amazon Web Services (AWS) S3 for exports and imports of catalog objects (optional)9. Knowledge check
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.